2017-06-19 61 views
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 

     }); 

回答

0

OK解決。我關掉了

db.Configuration.ProxyCreationEnabled = false; 

我不知道是不是正確的方法。但它解決了這個問題。自6個小時前我就一直在探討這個問題。在關閉此功能之後,您可以使用以下功能:

。我只是扔在原始的實體,並沒有做任何序列化的對象。