c# - 从控制器 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,
});
解决方案
推荐阅读
- mysql - SparkSQL 中的引用“column_name”不明确
- c# - 如何使用一个实例的方法但不同的构造函数参数c#调用Parallel.For
- html - 如何通过css内联属性在一行中显示两个div(类)
- api - Pinterest 重定向 URI
- c# - 每秒刷新和更新上下文菜单条
- r - 如何选择在 R 中显示变量的特定列(情节)?
- java - Selenium 完全找不到可见和可交互的元素
- python - 安装 sklearn 时获取“需要 Microsoft Visual C++ 14.0 或更高版本”
- python - 带有 keep_default_na 的 pd.read_csv 为 |: 'list' 和 'set' 抛出 TypeError
- python - AttributeError:类型对象'pandas._libs.tslibs.conversion._TSObject'没有属性'__reduce_cython__'