jqGrid参数。不能通过

时间:2011-04-10 19:50:50

标签: asp.net-mvc jqgrid

我调用web-service来填充jqGrid并希望将参数传递给它

我使用以下代码(客户端):

jQuery('#EmployeeTable').jqGrid({
    datatype: function () {
        var params = new Object();
        params.page = 10;
        params.Filter = true;
        params.DateStart = null;
        params.DateEnd = null;
        params.TagID = null;
        params.CategoryID = 3;
        params.StatusID = 1;
        params.IsDescription = true;
        $.ajax({
            url: '/Admin/IdeasJSON',
            type: "POST",
            contentType: "application/json; charset=utf-8",
            data: JSON.stringify(params),
            dataType: "json",
            success: function (data, st) {
                if (st == "success") {
                    var grid = $("#EmployeeTable")[0];
                    grid.addJSONData(data);
                }
            },
            error: function () {
                alert("Error with AJAX callback");
            }
        });
    },

另外,还有web-method(MVC)的推荐标准:

public JsonResult IdeasJSON(int? page, bool? Filter, DateTime? DateStart, DateTime? DateEnd, int? TagID, int? CategoryID, int? StatusID, bool? IsDescription)

为什么所有这些参数都为空?

[ADDED 04/11]

    jQuery(document).ready(function () {
        var StatusID = null, Filter = null, page = null, DateStart = null, DateEnd = null, TagID = null, CategoryID = null, IsDescription = null;
        if (jQuery.url.param('StatusID') != null) {
            StatusID = jQuery.url.param('StatusID');
        }

        if (jQuery.url.param('Filter') != null) {
            Filter = jQuery.url.param('Filter');
        }

        if (jQuery.url.param('page') != null) {
            page = jQuery.url.param('page');
        }

        if (jQuery.url.param('DateStart') != null) {
            DateStart = jQuery.url.param('DateStart');
        }

        if (jQuery.url.param('DateEnd') != null) {
            DateEnd = jQuery.url.param('DateEnd');
        }

        if (jQuery.url.param('TagID') != null) {
            TagID = jQuery.url.param('TagID');
        }

        if (jQuery.url.param('CategoryID') != null) {
            CategoryID = jQuery.url.param('CategoryID');
        }

        if (jQuery.url.param('IsDescription') != null) {
            IsDescription = jQuery.url.param('IsDescription');
        }



        jQuery('#EmployeeTable').jqGrid({
            url: '/Admin/IdeasJSON',
            datatype: 'json',
            postData: { page: page, Filter: Filter, DateStart: DateStart, DateEnd: DateEnd, TagID: TagID, StatusID: StatusID, CategoryID: CategoryID, IsDescription: IsDescription },
            jsonReader: {
                page: "page",
                total: "total",
                records: "records",
                root: "rows",
                repeatitems: false,
                id: ""
            },
            colNames: ['Logged By', 'Logging Agency (ID)', 'Title', 'Status', 'Points', 'Categories', 'Created Date', 'Description', 'Jira ID#', 'Portal Name', '', '', '', '', '', '', ''],
            colModel: [
                        { name: 'LoggedBy', width: 100 },
                        { name: 'LoggingAgencyID', width: 85 },
                        { name: 'Title', width: 100 },
                        { name: 'Status', width: 100 },
                        { name: 'Points', width: 40, align: 'center' },
                        { name: 'Categories', width: 100 },
                        { name: 'CreatedDate', width: 80, formatter: ndateFormatter },
                        { name: 'Description', width: 300 },
                        { name: 'JiraID', width: 55 },
                        { name: 'PortalName', width: 100 },
                        { name: 'IdeaID', width: 25, formatter: ActionDescriptionFormatter },
                        { name: 'IdeaID', width: 25, formatter: ActionEditFormatter },
                        { name: 'IdeaID', width: 25, formatter: ActionDeleteFormatter },
                        { name: 'IdeaGridCommentsAndSubideas', width: 25, formatter: ActionIdeaGridCommentsAndSubideas },
                        { name: 'IdeaGridCountVotes', width: 25, formatter: ActionIdeaGridCountVotes },
                        { name: 'IdeaGridCountVotes', width: 25, formatter: ActionIdeaGridLinkIdeas },
                        { name: 'IdeaGridCountVotes', width: 25, formatter: ActionIdeaGridIdeaType },
                    ],
            pager: '#EmployeeTablePager',
            width: 1000,
            viewrecords: true,
            caption: 'Idea List',
            excel: true
        }).jqGrid('navGrid', '#EmployeeTablePager', {
            add: false,
            edit: false,
            del: false,
            search: false,
            refresh: false
        }).jqGrid('navButtonAdd', '#EmployeeTablePager', {
            caption: " Export to Excel ",
            buttonicon: "ui-icon-bookmark",
            onClickButton: ReturnExcel,
            position: "last"
        }).jqGrid('navButtonAdd', '#EmployeeTablePager', {
            caption: " Export to CSV ",
            buttonicon: "ui-icon-bookmark",
            onClickButton: ReturnCSV,
            position: "last"
        });
    });

1 个答案:

答案 0 :(得分:1)

您不应使用datatype作为使用JSON数据的函数。可能你使用了非常古老的示例模板。

例如在the answer的“更新”部分,您可以找到完整的demo project,它演示了如何在ASP.MVC 2.0中使用jqGrid,包括分页,排序和过滤/高级搜索。

如果您想将一些其他参数作为jqGrid请求的一部分发布到服务器,则应使用postData

形式的postData: {CategoryID: 3, StatusID: 1, IsDescription:true, Filter: true}参数