我正在使用 jqgrid,我想从 jquery 显示网格调用控制器返回我的 json 数据我的网格没有显示数据代码在这里
我的控制器动作是这样的
private static List<Category> GetProducts(int parent, int childs)
{
string[] procat = { "Electrical", "Computer", "Furniture", "House Hold", "Automobiles" };
var data = new List<Category>();
for (int i = 0; i < parent; i++)
{
data.Add(new Category { CatId = i, CatName = procat[i % 5], Products = new List<Product>() });
for (int j = 0; j < childs; j++)
{
data[i].Products.Add(new Product
{
ProId = j,
ProName = "ABC",
desc = "A web browser built for speed, simplicity, and security",
desc1 = "Google Chrome",
desc2 = (i * j).ToString(),
desc3 = "Copyright 2013 Google Inc. All rights reserved.",
desc4 = i.ToString(),
desc5 = j.ToString(),
desc6 = "Google Chrome",
desc7 = (i * j).ToString(),
desc8 = "Copyright 2013 Google Inc. All rights reserved.",
desc9 = i.ToString(),
desc10 = j.ToString(),
desc11 = "Google Chrome",
desc12 = (i * j).ToString(),
desc13 = "Copyright 2013 Google Inc. All rights reserved.",
desc14 = i.ToString(),
desc15 = j.ToString(),
desc16 = "Google Chrome",
desc17 = (i * j).ToString(),
desc18 = "Copyright 2013 Google Inc. All rights reserved.",
desc19 = i.ToString(),
desc20 = j.ToString(),
desc21 = "Google Chrome",
desc22 = (i * j).ToString(),
desc23 = "Copyright 2013 Google Inc. All rights reserved.",
desc24 = i.ToString(),
desc25 = j.ToString()
});
}
}
return data;
}
public JsonResult PlainObjectsView()
{
var res = new List<FlatProduct>();
string[] procat = { "Electrical", "Computer", "Furniture", "House Hold", "Automobiles" };
int i = 1;
foreach (var item in procat)
{
res.Add(new FlatProduct
{
CatId = i,
CatName = item,
ProName = item,
ProId = i,
level = 0,
parent =null,
Isleaf = false,
IsLoaded = true,
Isexpanded = true
});
i++;
}
var data = GetProducts(5, 5);
foreach (var cats in data)
{
foreach (var prods in cats.Products)
{
res.Add(new FlatProduct
{
CatId = cats.CatId + 1,
CatName = cats.CatName,
ProId = prods.ProId,
ProName = prods.ProName,
desc = prods.desc,
desc1 = prods.desc1,
desc2 = prods.desc2,
desc3 = prods.desc3,
desc4 = prods.desc4,
desc5 = prods.desc5,
desc6 = prods.desc6,
desc7 = prods.desc7,
desc8 = prods.desc8,
desc9 = prods.desc9,
desc10 = prods.desc10,
desc11 = prods.desc11,
desc12 = prods.desc12,
desc13 = prods.desc13,
desc14 = prods.desc14,
desc15 = prods.desc15,
desc16 = prods.desc16,
desc17 = prods.desc17,
desc18 = prods.desc18,
desc19 = prods.desc19,
desc20 = prods.desc20,
desc21 = prods.desc21,
desc22 = prods.desc22,
desc23 = prods.desc23,
desc24 = prods.desc24,
desc25 = prods.desc25,
level = 1,
parent = cats.CatId + 1,
Isleaf = false,
IsLoaded = true,
Isexpanded = true
});
}
}
double pagesize = 5;
var finalRes = new { page = 1, records = res.Count, rows = res, total = Math.Ceiling(res.Count / pagesize), id = res.Select(c=>c.CatId), };
return Json(finalRes, JsonRequestBehavior.AllowGet);
}
我的jQuery是这样的
<script type="text/javascript">
$(document).ready(function () {
'use strict';
$("#treegrid").jqGrid({
url: '@Url.Content("~/TreeGrid/PlainObjectsView")',
datatype: "json",
mtype: "Get",
colModel: [
{ name: "CatId", width: 150,key:true, hidden:true},
{ name: "CatName", width: 200 },
{ name: "desc", width: 200 },
{ name: "desc1", width: 300 },
{ name: "desc10", width: 300 },
{ name: "desc11", width: 150 },
{ name: "desc12", width: 200 },
{ name: "desc13", width: 300 },
{ name: "desc14", width: 150 },
{ name: "desc15", width: 200 },
{ name: "desc16", width: 300 },
{ name: "desc17", width: 150 },
{ name: "desc18", width: 200 },
{ name: "desc19", width: 300 },
{ name: "desc2", width: 150 },
{ name: "desc20", width: 150 },
{ name: "desc21", width: 200 },
{ name: "desc22", width: 300 },
{ name: "desc23", width: 150 },
{ name: "desc24", width: 200 },
{ name: "desc25", width: 300 },
{ name: "desc3", width: 200 },
{ name: "desc4", width: 300 },
{ name: "desc5", width: 150 },
{ name: "desc6", width: 200 },
{ name: "desc7", width: 300 },
{ name: "desc8", width: 150 },
{ name: "desc9", width: 200 },
{ name: "ProId", width: 300, hidden:true },
{ name: "ProName", width: 150 }
],
treeGridModel: 'adjacency',
height: "auto",
ExpandColumn: 'CatName',
// ExpandColClick: true,
loadonce:true,
treeGrid: true,
// gridview: true,
viewrecords: true,
caption: "Tree Grid Example"
});
});
</script>
请帮帮我我哪里错了