Passing variables through URL in Jqgrid to controller in mvc
How do I pass values from url to Jqgrid, the issue is the Jqgrid needs to be loaded based on edit link on previous page, and we have the URL like:
http://localhost:49771/Search/EditSearchResults?id=ID_HelpTopics&action=edit
I need to be able to use this id in URL for populating the grid data, so I need to pass this value through grid to controller to get the results and the grid I have is like:
$("#list").jqGrid({
url: '<%= Url.Action("EditSearchResults", new {controller = "JSonData" }) %>',
datatype: 'json',
colNames: ['Language', 'ID'],
colModel: [
{ name: 'Language', index: 'Language', editable: false, width: 40, align: 'left', sortable: false },
{ name: 'ID', index: 'ID', width: 40, editable: true, edittype: "text", align: 'left', editoptions: { size: 5, maxlength: 30 }, sortable: false }, ],
editurl: '<%= Url.Action("EditSearchResults", new {controller = "JSONData"}) %>',
pager: '#pager',
//autowidth: true,
width: "500",
autowidth: true,
rowNum: 20,
height: "200",
loadonce: false,
rowList: [5, 10, 20, 50],
recordtext: "View Records {0} - {1} of {2}",
emptyrecords: "No records to view",
loadtext: "Loading...",
pgtext: "Page {0} of {1}",
sortname: 'Results',
sortorder: "desc",
viewrecords: true,
scroll: false,
loadonce: false,
caption: 'Edit Search Results',
ondblClickRow: function (id) {
if (id != null) {
jQuery('#grid').jqGrid('restoreRow', lastsel);
jQuery('#list').jqGrid('saveRow', id);
jQuery('#list').jqGrid('editRow', id, true, false, processEdit);
lastsel = id;
}
}
});
});
How can use the current URL to pass id to controller to populate jqgrid, 开发者_StackOverflow社区How should the controller and jqgrid should be like? Any ideas?
Url.Action will take a anonymous object as a parameter set
url: '<%= Url.Action("EditSearchResults",
new {controller = "JSonData" },
new {id = Request.Params[id] }) %>',
However it would be preferable to make that part of your model than depending on the Request.
精彩评论