[英]JQGrid not displaying JSON data when getting JSON data via AJAX
Mine is a MVC project. 我的是一个MVC项目。 From my view am making a AJAX call to get the JSON data. 我认为正在进行AJAX调用以获取JSON数据。 From my controller when i deseralize my class using javascriptDeserializer, i get below 当我使用javascriptDeserializer对类进行反序列化时,从控制器中获取以下内容
{
"page":1,
"total":2,
"records":2,
"rows":[
{"id":1,"cell":["ToolVersion","1","ESP","1.2","2/2/2013"]},
{"id":2,"cell":["ToolVersion","2","OPT","1.3","3/3/2013"]}
]
}
The action method as below 动作方法如下
var lst = obj.GetDetails(); // this returns the instance of MyCustomJQGrid class.
return Json(new
{
total = 2,
page = 1,
records = 2,
rows = lst.rows.ToArray()
}, JsonRequestBehavior.AllowGet);
public class MyCustoMJQGrid
{
public class Row
{
public int id { get; set; }
public List<string> cell { get; set; }
public Row()
{
cell = new List<string>();
}
}
public int page { get; set; }
public int total { get; set; }
public int records { get; set; }
public List<Row> rows { get; set; }
public JQGrid()
{
rows = new List<Row>();
}
}
in view, am using below code 鉴于,我正在使用下面的代码
$('#list2').jqGrid({
url: '@(Url.Action("GetToolVersionDetails", "Admin"))',
datatype: 'json',
colNames: ['TableName','RowId', 'ColA', 'ColB', 'ColC'],
mtype: 'GET',
colModel: [
{ name: 'TableName', index: 'TableName', width: 150 },
{ name: 'RowId', index: 'RowId', width: 150 },
{ name: 'ColA', index: 'ColA', width: 250 },
{ name: 'ColB', index: 'ColB', width: 250 },
{ name: 'ColC', index: 'ColC', width: 250 }
],
jsonReader: {
root: 'rows',
total: 'total',
page: 'page',
records: 'records',
cell: 'cell',
id: 'id',
repeatitems: false
},
rowNum: 10,
rowList: [5, 10, 20, 30],
pager: $('#gridpager'),
sortname: 'RowId',
viewrecords: true,
sortorder: 'asc',
caption: 'Tool Version',
shrinkToFit: true,
width: $('#gridContainer').width(),
height: 200,
hidegrid: false,
});
jqgrid is getting displayed with two empty rows. jqgrid的显示中有两个空行。 no data is displayed. 没有数据显示。 it just shows a blank table with two rows. 它只显示了两行的空白表。 JSON data is not getting displayed. JSON数据未显示。
Kindly help. 请帮助。
Thanks. 谢谢。
I suggest you to install and use MvcJqGrid
nuget package, to have a full featured fluent grid solution with mvc helpers. 我建议您安装并使用MvcJqGrid
nuget软件包,以使用mvc helper获得功能完善的流利网格解决方案。
It represents a repository class to select, filter and sort rows. 它表示用于选择,过滤和排序行的存储库类。 It also represents a GridSettings
type that you can simply use in your controller to put data rows into a json response and send it to the view. 它还表示一个GridSettings
类型,您可以在控制器中简单地使用它来将数据行放入json响应并将其发送到视图。
Codes for repository class are here . 存储库类的代码在这里 。 You also can find all other required codes there 您还可以在那里找到所有其他必需的代码
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.