从jQuery Grid插件将额外参数传递给ASP.NET MVC控制器操作

cod*_*dog 1 asp.net-mvc jquery jqgrid asp.net-mvc-3

我试图使用ASP.NET MVC的jQuery Grid插件来显示数据.看来web上提供的示例显示控制器动作签名如下所示:

public ActionResult SomeMethod(string sidx, string sord, int page, int rows) { }
Run Code Online (Sandbox Code Playgroud)

有什么办法可以从页面上的各个输入字段传递额外的参数吗?

干杯,D.

补充:我还没有编写任何代码,但客户端代码将是这样的:

jQuery(document).ready(function(){ 
      jQuery("#list").jqGrid({
        url:'/Entry/GridData/',
        datatype: 'json',
        mtype: 'POST',
        colNames:['Entry Date','Registration','Registered Name'],
        colModel :[
          {name:'EntryDate', index:'EntryDate', width:40 },
          {name:'Registration', index:'Registration', width:200 },
          {name:'RegisteredName', index:'RegisteredName', width:200 }],
        pager: jQuery('#pager'),
        rowNum:20,
        rowList:[5,10,20,50],
        altRows: true,
        sortable: false,
        viewrecords: true,
        caption: 'My first grid'
      }); 
    });
Run Code Online (Sandbox Code Playgroud)

服务器端代码如下:

public ActionResult GridData(string sidx, string sord, int page, int rows)
{
    //Some stuff to get data, which needs a couple of extra parameters on top of the ones in the signature
    return Json(dataCollection);
}
Run Code Online (Sandbox Code Playgroud)

在GridData操作中,我需要更多参数来获取适当的数据.如何在javascript中指定这些,以及如何在控制器操作中获取它们?

Dar*_*rov 8

您可以使用该postData属性:

$('#list').jqGrid({
    url: '@Url.Action("SomeMethod")',
    datatype: 'json',
    mtype: 'POST'
    postData: { 
        someParam1: $('#someInput1').val(),
        someParam2: $('#someInput2').val() 
    }
    ...
});
Run Code Online (Sandbox Code Playgroud)

并在您的控制器操作中,您可以添加此参数:

public ActionResult SomeMethod(string someParam1, string someParam2, string sidx, ...) { }
Run Code Online (Sandbox Code Playgroud)