【问题标题】:jqGrid getting data from url optionjqGrid 从 url 选项获取数据
【发布时间】:2013-02-26 20:39:41
【问题描述】:

我最难从我的 url 中提取数据并将其放入我的 jqGrid 中的 asp.net MVC4 中。我在这里错过了什么?

    $(document).ready(function () {
        jQuery("#frTable").jqGrid ({
            cmTemplate: { sortable: false },
            caption: '@TempData["POPNAME"]' + ' Population',
            url: '@Url.Action("GetAjaxPagedGridData", "Encounters", new { popId = TempData["POPULATIONID"] })',//'/Encounters/GetAjaxPagedGridData/'+ '',
            datatype: "jsonstring",
            mtype: 'GET',
            pager: '#pager',
            height: '450',
            ...

然后你进入 colNames 和 colModels 以及所有与这个特定查询无关的东西。这是返回我的数据的方法。我只想说我做客户端分页的东西似乎有效。但除非我能真正看到数据,否则我无法验证?

我在这里做错了什么?

    public string GetAjaxPagedGridData(int page, int rows, int popId) {
        string userID = HttpContext.User.Identity.Name;
        DataRepository dr = new DataRepository();
        string encounter = dr.Get(popId, userID, "1", page, rows, "");
        return encounter;
    }

【问题讨论】:

    标签: asp.net-mvc-4 jqgrid


    【解决方案1】:

    你可以在表单中使用jqGrid的postData选项

    postData: {
        popId: 123
    }
    

    或以形式

    postData: {
        popId: function () {
            return 123;
        }
    }
    

    您应该另外使用datatype: "json" 而不是datatype: "jsonstring"

    【讨论】:

    • 我不知道它是什么,但是当我将数据类型放入我的选项时,我总是得到这个异常......'Microsoft JScript 运行时错误:无法获取属性'0'的值: object is null or undefined' 很确定这是不好的。
    • @DmainEvent:该异常可能意味着许多其他错误,例如您从GetAjaxPagedGridData 返回的错误格式数据或您使用的 JavaScript 文件的错误顺序。见the documentation
    猜你喜欢
    • 1970-01-01
    • 2014-07-08
    • 1970-01-01
    • 2012-06-20
    • 1970-01-01
    • 2011-11-17
    • 1970-01-01
    • 2018-01-31
    • 1970-01-01
    相关资源
    最近更新 更多