Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JQGrid在通过AJAX获取JSON数据时不显示JSON数据_Json_Jquery_Jqgrid - Fatal编程技术网

JQGrid在通过AJAX获取JSON数据时不显示JSON数据

JQGrid在通过AJAX获取JSON数据时不显示JSON数据,json,jquery,jqgrid,Json,Jquery,Jqgrid,Mine是一个MVC项目。在我看来,我正在进行AJAX调用以获取JSON数据。当我使用javascriptDeserializer反序列化我的类时,我从我的控制器得到如下信息 { "page":1, "total":2, "records":2, "rows":[ {"id":1,"cell":["ToolVersion","1","ESP","1.2","2/2/2013"]}, {"id":2,"cell":["ToolVers

Mine是一个MVC项目。在我看来,我正在进行AJAX调用以获取JSON数据。当我使用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"]}
    ]
}
操作方法如下所示

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>();
    }
}
jqgrid显示为两个空行。不显示任何数据。它只显示一个有两行的空白表。未显示JSON数据

请帮忙


谢谢。

我建议您安装并使用
MvcJqGrid
nuget软件包,以获得一个功能齐全的带有mvc助手的fluent grid解决方案

它表示用于选择、筛选和排序行的存储库类。它还表示一种
GridSettings
类型,您可以在控制器中简单地使用该类型将数据行放入json响应并将其发送到视图

例如


存储库类的代码为。您还可以在那里找到所有其他必需的代码

我建议您安装并使用
MvcJqGrid
nuget软件包,以获得一个功能齐全的带mvc助手的fluent grid解决方案

它表示用于选择、筛选和排序行的存储库类。它还表示一种
GridSettings
类型,您可以在控制器中简单地使用该类型将数据行放入json响应并将其发送到视图

例如


存储库类的代码为。您还可以在那里找到所有其他必需的代码

问题是json格式的。我们需要有列名和值,这样才能工作。否则我们应该设置Repeatvalues=true。问题是json格式。我们需要有列名和值,这样才能工作。否则,我们应该将Repeatvalues设置为true。
$('#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,
    });