0
我打電話給一個方法,它返回一個相當有一個字段子實體的實體。我不需要子實體,但因爲它們處於關係中,所以我無法獲取它的rip。Jquery數據庫Json錯誤
當我檢查json數據時,我正確得到響應。但是當我在數據表中設置斷點時。
mRender: function (data, type, row) {
行通過JSON數據CHAR BY CHAR循環
`
$('#serviceTB').DataTable({
"processing": true,
"serverSide": true,
destroy: true,
searching: true,
"info": true,
"pageLength": 10,
"lengthMenu": [[10, 20, 50, -1], [10, 20, 50, "All"]],
"sDom": "<'top'f>rt<'fluid-row'<'col-md-5 col-sm-12'i><'col-md-7 col-sm-12'p>><'fluid-row'<'col-md-12 col-sm-12'<'pull-right'l>>>",
"columns": [
{ "data": "article_number", "orderable": true, "searchable": true },
{ "data": "serial_number", "orderable": true, "searchable": true },
{ "data": "description", "orderable": false, "searchable": false },
{ "data": "Purchase_date", "orderable": true, "searchable": false },
{ "data": "rental_agreement", "orderable": false, "searchable": true },
{ "data": "service_agreement", "orderable": false, "searchable": true },
{ "data": "Warranty", "orderable": true, "searchable": true },
/* EDIT */ {
mRender: function (data, type, row) {
debugger
}
},
], "ajax": {
"url": "@Url.Action("GetMachineOwnerByType", "WMFMachine")",
"type": "GET"
}
});
}`
下面是我的JSON結果裏面包含了所有由jQuery的
public JsonResult GetMachineOwnerByType(int draw, int start, int length, string searchstring = "", string orderstring = "", int ordercol = 0)
{
string search = Request.QueryString["search[value]"];
string order = Request.QueryString["order[0][dir]"];
int sortColumn = int.Parse(Request.QueryString["order[0][column]"]);
searchstring = search;
orderstring = order;
ordercol = sortColumn;
var result = service.GetListWMFMachineByType(draw, start, length, searchstring, orderstring, ordercol, "M");//mylogic to get the Model
return new JsonResult { Data = result, MaxJsonLength = Int32.MaxValue, JsonRequestBehavior = JsonRequestBehavior.AllowGet };
}
所需的字段` 型號CLass
public class JsonTableModel
{
public int draw { get; set; }
public int recordsTotal { get; set; }
public int recordsFiltered { get; set; }
public object data { get; set; }
}
邏輯
dt.data = JsonConvert.SerializeObject(mymodel, Formatting.None,
new JsonSerializerSettings()
{
ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore,
PreserveReferencesHandling = PreserveReferencesHandling.None
});