0%

【MVC】回傳Json格式,並用JQuery解讀

View中回傳Json格式的物件 ```csharp
var jsonObject = JsonConvert.SerializeObject(Repository.GetExhibitionList().OrderBy(o => o.CreateDate).ToArray());
return Json(jsonObject);

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

JQuery中解讀 ```javascript
var List = $.parseJSON(returnvalue);

var tr = [];
//轉換日期格式
$.each(List, function (index, val) {

tr.push('<tr class="exhibitionItem">' +
'<td>' + (index + 1) + '</td>' +
'<td>' + val.ExhibitionName + '</td>' +
'<td>' + val.CreateDate + '</td>' +
'<td>' + val.EditDate + '</td>' +
'</tr>');
});