从jQuery Grid插件向ASP.NET MVC控制器操作传递额外的参数 [英] Passing extra parameters to ASP.NET MVC controller action from jQuery Grid plugin
问题描述
我正在尝试将jQuery Grid插件与ASP.NET MVC一起使用以显示数据. Web上提供的示例似乎表明,控制器操作签名如下所示:
I am trying to use jQuery Grid plugin with ASP.NET MVC to display data. It seems examples provided on the web shows that the controller action signature looks like this:
public ActionResult SomeMethod(string sidx, string sord, int page, int rows) { }
有什么办法可以从页面上的各个输入字段传递额外的参数?
Is there any way I can pass extra parameters from various input fields on the page?
干杯, D.
已添加:我尚未编写任何代码,但客户端代码将类似于:
ADDED: I have not written any code yet but the client side code will be something like:
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中指定这些内容,以及如何在控制器操作中获取它们?
In the GridData action I need a couple more parameters to get the appropriate data. How do I specify these in the javascript, and how do I get hold of them in the controller action?
推荐答案
您可以使用postData
属性:
$('#list').jqGrid({
url: '@Url.Action("SomeMethod")',
datatype: 'json',
mtype: 'POST'
postData: {
someParam1: $('#someInput1').val(),
someParam2: $('#someInput2').val()
}
...
});
,然后在控制器操作中可以添加以下参数:
and in your controller action you could add this parameter:
public ActionResult SomeMethod(string someParam1, string someParam2, string sidx, ...) { }
这篇关于从jQuery Grid插件向ASP.NET MVC控制器操作传递额外的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!