Reputation: 2467
When I use editurl property in my jqgrid, the controller action gets called after I hit submit button on adding a new row. But how do I get all the grid rows there? Which parameter should I read from my controller action method in order to get the grid data?
Grid code:
$("#list1").jqGrid({
url: '/CMS/GetCustomLanguageData',
---
---
editurl: '/CMS/SaveCustomLanguageData'
---
Add new row code:
grid.jqGrid('editGridRow',"new",{height:280,reloadAfterSubmit:false,addCaption: "Add Record",
editCaption: "Edit Record",
bSubmit: "Submit",
bCancel: "Cancel",
bClose: "Close",
saveData: "Data has been changed! Save changes?",
bYes : "Yes",
bNo : "No"
});
Controller code:
public ActionResult SaveCustomLanguageData()
{
}
Upvotes: 4
Views: 6117
Reputation: 222017
jqGrid send to the controller named parameters with the name as you defined in the 'name' property of the colModel
. Additionally will be send oper=add
and id=_empty
. So your controller action can look like following
public JsonResult SaveCustomLanguageData (string id, string oper, MyObject item)
{
// test id for "_empty" or oper for "add".
// If so add the item and return the value of the new id
// for example return Json ("123");
}
on the client side you should decode the JSON response for example with the following code
jQuery.extend(jQuery.jgrid.edit, {
afterSubmit: function (response, postdata) {
return [true, "", jQuery.parseJSON(response.responseText)];
}
});
Upvotes: 4