【问题标题】:jqGrid doesn't load for one data setjqGrid 不会为一个数据集加载
【发布时间】:2014-06-06 03:33:38
【问题描述】:

在我们开发的 MVC4 门户网站上有许多 jqGrid。它对所有这些都很好,除了一个。它显示网格,但没有数据,也没有寻呼机。我已经为此绞尽脑汁好几天了,我看不出有什么问题。它使用与其他所有工作正常的网格相同的 jQuery 和控制器结构。这是我所拥有的:

jQuery/HTML:

<table id="OrgUnitTableGrid"></table>
<div id="OrgUnitTableGridPager"></div>

<script>
    $(function () {
        $("#OrgUnitTableGrid").jqGrid({
            url: '@Url.Action("OrgDataGridView2", "Home")',
            dataType: 'json',
            mtype: 'GET',
            colNames: ['Pos ID', 'Position Name', 'Eff Date', 'ANZSCO', 'Function', 'Location', 'Reports To'],
            colModel: [
                { name: 'PositionID', width: "70", sortable: true, align: 'left' },
                { name: 'PositionName', width: "150", sortable: true, align: 'left' },
                { name: 'EffectiveDate', width: "50", sortable: true, align: 'left' },
                { name: 'ANZSCO', width: "170", sortable: true, align: 'left' },
                { name: 'Function', width: "130", sortable: true, align: 'left' },
                { name: 'Location', width: "170", sortable: true, align: 'left' },
                { name: 'ReportsTo', width: "70", sortable: true, align: 'left' },
            ],
            rowNum: 20,
            rowList: [20, 50, 100],
            width: "900",
            height: '530px',
            pager: '#OrgUnitTableGridPager',
            sortname: "Pos ID",
            sortorder: "asc",
            edit: false,
            viewrecords: true,
            jsonReader: {
                repeatitems: "false",
                id: "0",
            }
        });

        jQuery("#OrgUnitTableGrid").jqGrid('navGrid', '#OrgUnitTableGridPager', { edit: false, add: false, del: false });

    });
</script>

这里是对应的Controller动作

public ActionResult OrgDataGridView2()
{
    WebPortalEntities db = new WebPortalEntities();

    int page = int.Parse(Request.Params["page"]);
    int rp = int.Parse(Request.Params["rows"]);

    string sortname = Request.Params["sidx"];
    string sortorder = Request.Params["sord"];
    string searchText = Request.Params["searchValue"];

    IEnumerable<OrgDataViewModel> rows = db.OrgDatas.OrderBy(p => p.PositionID).Select(p => new OrgDataViewModel
    {
        PositionID = p.PositionID,
        PositionName = p.PositionName,
        EffectiveDate = p.EffectiveDate,
        ANZSCO = p.ANZSCO,
        Function = p.Function,
        Location = p.Location,
        ReportsTo = p.ReportsTo,
    }).Skip((page - 1) * rp);

    int total = (rows.Count() / rp) + 1;
    rows = rows.Take(rp);

    JsonResult retVal = Json(new { page, total, rows }, JsonRequestBehavior.AllowGet);
    return retVal;
}

当我检查创建的 JSon 时,它有数据并且看起来很好。我已经搜索了 StackOverflow 和整个网络,但我没有发现任何似乎有效的东西。这只是令人困惑,因为我的其他网格都遵循相同的范例工作正常。救命!

【问题讨论】:

    标签: jquery asp.net-mvc jqgrid


    【解决方案1】:

    我终于找到了。这很愚蠢。

    代替:

    datatype: 'json',
    

    我有

    dataType: 'json',
    

    在客户端的jQuery中。一个字母错了,jqGrid 的默认数据类型是 XML,这就是它在 loadError 事件中抛出 parsererror 的原因。这是一个适合年轻(而且年龄稍大;))玩家的陷阱。

    【讨论】:

    • 这为我节省了很多时间,我花了半天时间试图弄清楚为什么我无法将数据加载到我的网格中,然后我看到了这个。
    猜你喜欢
    • 2012-03-22
    • 2011-08-05
    • 2017-01-27
    • 2011-08-11
    • 2018-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多