1

我似乎无法弄清楚如何根据 URL 中的参数中的 Id 加载 jqGrid。基本上我有地址 \Locations\Departmetn?LocationId=1 现在我想根据位置 ID 加载网格。网格只是使用地址 \Locations\GetDepartments 让控制器将数据作为 jSonResult 返回,这一切正常,我只是不知道如何/是否可以将位置 ID 发送到该 URL \Locations\GetDepartments

$(function () {

    $.widget('qs.department_page', {

    _create: function () {

        var self = this;
        this.scroll_to_end = false;

        var LocId = 1; //hardcoded for the test

        // get my child dom elements
        this.department_pager = $("#department_pager");

        // set up the grid and pager
        this.department_grid = $("#department_grid").jqGrid(
        {
            url: "/Location/GetDepartments/",
            datatype: "json",
            mtype: "POST",
            height: 300,
            hidegrid: false,
            colNames: ['Name', 'Site Num', 'Description', 'ABN'],
            colModel: [
                { name: 'Name', index: 'Name', width: 200, align: "left", sortable: false },
                { name: 'SiteNum', index: 'SiteNum', width: 100, align: "left", sortable: false },
                { name: 'Company', index: 'Company', width: 200, align: "left", sortable: false },
                { name: 'ABN', index: 'ABN', width: 200, align: "left", sortable: false }
            ],
            caption: "Departments",
            pager: this.department_pager
        })
        .navGrid('#department_pager', {
            addfunc: function () { self.onNewDepartment(); },
            editfunc: function (val) { self.onEditDepartment(val); },
            search: false,
            refresh: false
        },
            {/*add*/
            },
            {/*edit*/
            },
            { url: "/Location/DeleteDepartment" }
        );

}

4

2 回答 2

1

下面有很多方法,一种方法,

调用 beforerequest 并扩展 postadata。在控制器中,您将获得 LocationID 值。

 beforeRequest: function () {

                var postData = $('#department_grid').jqGrid('getGridParam', "postData");
                $.extend(postData, { LocationID: "give your location id" });
            },

希望这会解决。

于 2013-02-22T10:57:21.990 回答
0

如果您考虑使用休息服务来使用 /Location/Departments/{Id} 之类的链接怎么办?

于 2013-02-22T10:57:23.747 回答