为何jqgrid前台不显示数据啊?----在线等
$('#table').jqGrid({
url: 'Test/TestAction',
mtype: 'POST', // 这里GET和POST都试过
datatype: 'json',
autowidth: true,
autoheight: true,
caption: 'Test',
colNames: ['编号', '类型ID', '类型名称', '类型值', '备注'],
colModel: [
{ name: 'ID', width: 75, sortable: false },
{ name: 'TypeID', width: 90, sortable: false },
{ name: 'TypeName', width: 100, sortable: false },
{ name: 'TypeValue', width: 80, align: "right", sortable: false },
{ name: 'TypeBZ', width: 200, align: "right", sortable: false }
]
});
后台代码(试过net自带的json序列化,用下面的Newtonsoft的Json组件,也没法显示数据)
public JsonResult TestAction()
{
string str = Newtonsoft.Json.JsonConvert.SerializeObject
(dictionaryService.GetAll_DM_WEBCONFIG());
JsonResult jr = Json(str, JsonRequestBehavior.AllowGet);
return jr;
}
在前台的jqgrid的loadComplete事件里面看了下,数据是确实传到前台了的
格式如下:
[{"ID":1,"TypeID":1,"TypeName":"Top","TypeValue":1,"TypeBZ":"测试一"},{"ID":2,"TypeID":1,"TypeName":"Left","TypeValue":1,"TypeBZ":"测试二"},{"ID":3,"TypeID":1,"TypeName":"Right","TypeValue":1,"TypeBZ":"测试三"},{"ID":4,"TypeID":1,"TypeName":"Bottom","TypeValue":1,"TypeBZ":"测试四"},{"ID":5,"TypeID":5,"TypeName":"5","TypeValue":5,"TypeBZ":"5"},{"ID":6,"TypeID":6,"TypeName":"6","TypeValue":6,"TypeBZ":"6"},{"ID":7,"TypeID":7,"TypeName":"7","TypeValue":7,"TypeBZ":"7"},{"ID":8,"TypeID":8,"TypeName":"8","TypeValue":8,"TypeBZ":"8"},{"ID":9,"TypeID":9,"TypeName":"9","TypeValue":9,"TypeBZ":"9"},{"ID":11,"TypeID":11,"TypeName":null,"TypeValue":null,"TypeBZ":null},{"ID":12,"TypeID":12,"TypeName":null,"TypeValue":null,"TypeBZ":null}]
把上面的json定义为本地变量的话,采用local方式是可以显示数据的,但如果采用url方式,就始终显示不了。
------解决方案--------------------DEMO
------解决方案--------------------
具体原因不好说,你用firebug or Fiddler 跟踪一下