0

我正在尝试实现一个从我的控制器获取信息的 JQGrid,遵循本教程中的方法,http ://haacked.com/archive/2009/04/13/using-jquery-grid-with-asp.net- mvc.aspx

我的控制器的代码是:

    public ActionResult GridData(string sidx, string sord, int page, int rows)
    {
        var jsonData = new
        {
            total = 1,  
            page = page,
            records = 1, 
            rows = new[]
            {
                new {id = 1, cell = new[] {"", "", "", "", "", "", "f", "", "", "", "",     "", "", ""}},
            }
        };
        return Json(jsonData, JsonRequestBehavior.AllowGet);
    }

我的视图的代码是:

<link rel="stylesheet" type="text/css" media="screen" href="css/ui-lightness/jquery-ui-    1.8.23.custom.css" />
<link rel="stylesheet" type="text/css" media="screen" href="css/ui.jqgrid.css" />
<link rel="stylesheet" type="text/css" media="screen" href="css/ui.multiselect.css" />

<script src="js/jquery-1.7.2.min.js" type="text/javascript"></script>
<script src="js/i18n/grid.locale-en.js" type="text/javascript"></script>
<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>

<script type="text/javascript">
jQuery(document).ready(function ()
{
    jQuery("#list").jqGrid(
        {
            url: '/WebFormUserList/GridData',
            datatype: 'json',
            mtype: 'GET',
            colNames:
                [
                    'User_ID', 'Forename', 'Surname', 'Client_Code', 'User_Name',
                    'Password', 'Email', 'Gender', 'Report_Date', 'Email_Date',
                    'Test_Count', 'Test_Completed', 'Job_Function', 'Lookup_Value'
                ],
            colModel:
                [
                    { name: 'User_ID', index: 'User_ID', width: 'auto', align: 'centre' },
                    { name: 'Forename', index: 'Forename', width: 'auto', align: 'centre' },
                    { name: 'Surname', index: 'Surname', width: 'auto', align: 'centre' },
                    { name: 'Client_Code', index: 'Client_Code', width: 'auto', align: 'centre' },
                    { name: 'User_Name', index: 'User_Name', width: 'auto', align: 'centre' },
                    { name: 'Password', index: 'Password', width: 'auto', align: 'centre' },
                    { name: 'Email', index: 'Email', width: 'auto', align: 'centre' },
                    { name: 'Gender', index: 'Gender', width: 'auto', align: 'centre' },
                    { name: 'Report_Date', index: 'Report_Date', width: 'auto', align: 'centre' },
                    { name: 'Email_Date', index: 'Email_Date', width: 'auto', align: 'centre' },
                    { name: 'Test_Count', index: 'Test_Count', width: 'auto', align: 'centre' },
                    { name: 'Test_Completed', index: 'Test_Completed', width: 'auto', align: 'centre' },
                    { name: 'Job_Function', index: 'Job_Function', width: 'auto', align: 'centre' },
                    { name: 'Lookup_Value', index: 'Lookup_Value', width: 'auto', align: 'centre' },
                ],

            pager: jQuery('#pager'),
            height: 'auto',
            width: 1000,
            rowNum: 10,
            rowList: [5, 10, 20, 50],
            sortname: 'Id',
            sortorder: "desc",
            viewrecords: true,
            imgpath: '/css/ui-lightness/images',
            caption: 'My first grid'
        });
});

当我尝试调用网格页面时,出现以下错误。

参数字典包含“HFI_Assessment_Administration”中方法“System.Web.Mvc.ActionResult GridData(System.String, System.String, Int32, Int32)”的不可为空类型“System.Int32”的参数“页面”的空条目.Controllers.WebFormUserListController'。可选参数必须是引用类型、可空类型或声明为可选参数。参数名称:参数

我将非常感谢人们可以提供的任何帮助或建议。如果有人还可以解释 sidx、sord、page、rows 是如何传递的,那也将极大地帮助我理解。

非常感谢!

4

1 回答 1

0

page在您的示例中未初始化。尝试这个:

        page  = 1,
        records = 1, 
        rows = new[]
        {
            new {id = 1, cell = new[] {"", "", "", "", "", "", "f", "", "", "", "",     "", "", ""}},
        }
于 2012-09-25T15:54:08.763 回答