首页 > 解决方案 > 从控制器 ASP.Net MVC 5 绑定 jqGrid 中的问题

问题描述

我的问题与这个问题非常相似。我尝试了他建议的解决方案,但没有运气。

如果我删除序列化,那么我会收到错误消息:

序列化“System.Reflection.RuntimeModule”类型的对象时检测到循环引用

如果我序列化数据,那么我会得到一个空网格。我正在使用 jQuery 网格在我的应用程序中绑定一个 DataTable。

public ActionResult FetchData(string item)
{
  Repository o = new Repository();
  DataTable dt = new DataTable();
  dtEDIs = o.GetData(item);

  JsonSerializerSettings jss = new JsonSerializerSettings { 
    ReferenceLoopHandling = ReferenceLoopHandling.Ignore 
  };
  var result = JsonConvert.SerializeObject(dtEDIs, Formatting.Indented, jss);
  var jsonData = new
  {
    total = 10,
    page = 1,
    records = dt.Rows.Count,
    rows = result 
  };
  return Json(jsonData, JsonRequestBehavior.AllowGet);
}
<table id="jQGridDemo"></table>
$("#jQGridDemo").jqGrid({
  url: '/MyController/MyAction',
  datatype: 'json',
  mtype: 'get',
  postData: {
    itemNo: itemNo
  },
  colNames: ['ITEMNO', 'LOC', 'REQDATE'],
  colModel: [{
    name: "ItemNo"
  }, {
    name: "LOC"
  }, {
    name: "REQDATE"
  }],
  height: '100%',
  rowNum: 10,
  viewrecords: true,
  caption: 'JQgrid',
  emptyrecords: 'No records',
  jsonReader: {
    root: "rows",
    page: "page",
    total: "total",
    records: "records",
    repeatitems: false,
    Id: "0"
  },
  autowidth: true,
});

标签: c#jqueryasp.net-mvcjqgrid

解决方案


推荐阅读