错误截图
原因分析:
1.datagrid里使用时json格式要求有total和rows。
2.datagrid只能显示controller返回来的json对象。
错误代码:
Controller中Action返回给datagird的数据,将DataGrid对象转换为Json字符串
DataGrid dg = new DataGrid { total = rowsCount, rows = Lists, footer = null }; //将Json对象转换为Json字符串 string dgJson = DataHelper.ObjToJson(dg); return Json(dgJson, JsonRequestBehavior.AllowGet);
错误原因:对db对象转换为Json字符串后,前端datagrid无法识别转换后的Json字符串。在浏览器中查看数据如下:
修改:去掉string dgJson = DataHelper.ObjToJson(dg)语句,直接将dg对象以return Json的形式传给datagrid。在浏览器中查看数据如下:
参考文章: