我正在尝试使用带有ASP.NET MVC的jQuery Grid插件来显示数据。似乎网络上提供的示例显示控制器操作签名如下所示:
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中指定这些,以及如何在控制器操作中获取它们?
答案 0 :(得分:8)
您可以使用postData
属性:
$('#list').jqGrid({
url: '@Url.Action("SomeMethod")',
datatype: 'json',
mtype: 'POST'
postData: {
someParam1: $('#someInput1').val(),
someParam2: $('#someInput2').val()
}
...
});
并在您的控制器操作中添加此参数:
public ActionResult SomeMethod(string someParam1, string someParam2, string sidx, ...) { }
答案 1 :(得分:1)
创建与特定输入的目的相对应的另一个操作方法,并接受您要接受的参数。如果您需要在处理其他结果时返回此操作结果,请调用RedirectToRoute