我正在嘗試使用jQuery Grid插件與ASP.NET MVC來顯示數據。這似乎提供了在網絡上的實例表明,該控制器動作簽名如下所示:從jQuery Grid插件向ASP.NET MVC控制器動作傳遞額外參數
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中指定這些內容,以及如何在控制器操作中獲取它們?
太棒了!在發佈問題更新後不久,我看到了postData:屬性。它看起來很有希望,但我猜mtype:屬性必須設置爲'POST'?或者這也適用於GET? – codedog
@DanyW,我認爲它也可以和GET一起工作,但不是100%肯定的,還沒有測試過。如果沒有,你可以追加到URL:'url:'@ Url.Action(「SomeMethod」)?' + $ .param({someparam:'some value'})' –
工作就像一個魅力!它也適用於GET,只要返回JsonRequestBehavior.AllowGet指定!我不需要將其附加到網址。再次感謝! – codedog