我正在尝试使用 jQuery Grid 插件和 ASP.NET MVC 来显示数据。网络上提供的示例似乎表明 Controller 操作签名如下所示:
public ActionResult SomeMethod(string sidx, string sord, int page, int rows) { }
有什么方法可以从页面上的各个输入字段传递额外的参数吗?
干杯, 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'
});
});
服务器端代码如下:
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);
}
在 GridData 操作中,我需要更多参数来获取适当的数据。如何在 javascript 中指定这些,以及如何在 Controller 操作中获取它们?
最佳答案
您可以使用 postData
属性:
$('#list').jqGrid({
url: '@Url.Action("SomeMethod")',
datatype: 'json',
mtype: 'POST'
postData: {
someParam1: $('#someInput1').val(),
someParam2: $('#someInput2').val()
}
...
});
并且在您的 Controller 操作中您可以添加此参数:
public ActionResult SomeMethod(string someParam1, string someParam2, string sidx, ...) { }
关于jquery - 从 jQuery Grid 插件将额外参数传递给 ASP.NET MVC Controller 操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4983169/