0
返回JSON數據從控制器我有一個控制器,它返回一個模型作爲JSON對象模型:處理在ASP.NET
[HttpGet("{id}")]
[Route("GetById")]
public async Task <JsonResult> GetById([FromQuery]string id)
{
var myfoo = new {foo="bar", baz="Blech"};
return Json(myfoo);
}
如何處理jQuery中返回的JSON對象?
<script type="text/javascript">
$('#id').change(function() {
var id = $('#id').val();
if (id.length = 17) {
$.ajax(
{
url: '/Home/GetById?id=' + id,
type: 'GET',
jsondata: "",
contentType: 'application/json; charset=utf-8',
success: function (jsondata) {
alert("foo is: " + jsondata); <---?
},
error: function() {
//alert("error");
}
});
}
});
</script>
我需要得到富價值和分配到一個HTML控件
在此先感謝