我只是尝试在我的网站中使用 jqgrid。我正在使用vs 2013,asp.net mvc 5,并从nuget安装了jqgrid和jqgridmvc(jqgrid mvc helper)。我按照 jqgridmvc 制造商的示例(使用 xml 作为源),它工作正常: http ://mvcjqgrid.skaele.it/Home/TreeGrid
但是,当我尝试使用 json 作为源时,不知何故它不起作用。我怀疑我的 json 格式是错误的,但我不确定在哪里:
控制器代码:
public JsonResult TreeGridData(GridSettings gridSettings)
{
var jsonData = new
{
total = 1,
page = 1,
records = 2,
rows = new[]{
new {id = 1, cell = new object[] {"1", "root 1", "0", null, false, false, true}},
new {id = 11, cell = new object[] {"11", "child 11", "1", "1", true,false, true}}
}
};
return Json(jsonData, JsonRequestBehavior.AllowGet);
}
查看代码:
@(Html.Grid("treeGrid")
.SetCaption("TreeGrid")
.AddColumn(new Column("ItemID")
.SetLabel("Id").SetKey(true))
.AddColumn(new Column("Name")
.SetAsExpandable())
.SetUrl(Url.Action("TreeGridData"))
.EnableTreeGrid()
)
谢谢!
编辑:根据评论中的建议,我添加了从控制器生成的响应(www.localhost .../controller/treegriddata):
{
"total":1,
"page":1,
"records":2,
"rows":
[{"id":1,"cell":["1","root 1","0",null,false,false,true]},
{"id":11,"cell":["11","child 11","1","1",true,false,true]}]
}