Reputation: 2853
The Get, Edit and Delete all work fine. But add will not call into my ActionResult method. I am using the inline add that displays a modal form for new record values. There seem to be very few examples of how this works with the pager/form method that is provided in the latest jqGrid release. What am I missing for add/insert here?
html:
$("#grid").jqGrid({
url: 'ABC.Admin/CourseAdmin/GetLocationData/',
datatype: 'json',
jsonReader: { repeatitems: false },
mtype: 'GET',
colNames: ['Location Id', 'Name', 'Address Line 1'],
colModel: [
{ name: 'LocationId', index: 'LocationId', width: 40, key: true },
{ name: 'LocationName', index: 'LocationName', width: 150, editable: true },
{ name: 'AddressLine1', index: 'AddressLine1', width: 150, editable: true },
],
pager: jQuery('#pager'),
rowNum: 20,
sortname: 'Name',
sortorder: "asc",
viewrecords: true,
caption: '***Testing***',
height: 200,
loadonce: true, // needs to be true for client side paging to work
autowidth: true,
loadtext: 'Loading...'
})
$("#grid").jqGrid('navGrid', '#pager', { edit: true, add: true, del: true },
{ // edit options
url: 'ABC.Admin/CourseAdmin/SaveLocation/',
closeAfterEdit: true
},
{ // add
url: 'ABC.Admin/CourseAdmin/Create/'
},
{ //delete
url: 'ABC.Admin/CourseAdmin/DeleteLocation/',
closeOnEscape: true
}
);
controller:
public ActionResult Create(int id, string locationName, string addressLine1)
[HttpPost]
public ActionResult CreateLocation(string oper, string id, string locationName, string addressLine1) {
//Models.LocationProvider lp = new Models.LocationProvider();
//bool saved = lp.InsertLocation(location);
bool saved = false;
if (!saved)
{
Response.StatusCode = 500;
return Content("Record not saved!");
}
else
{
return Json(false);
}
}
Upvotes: 1
Views: 1834
Reputation: 2853
I got it worked out. The types on the parameters in the Create method sig were mismatched. They need to be all strings. Changing my controller to the following works. I also noticed that the id and oper params are picked up by name, not order - so I can put them either first or last (or wherever) in the signature and they get the correct values - cool!. I will edit my original post with this correction.
public ActionResult Create(string oper, string id, string locationName, string addressLine1)
For anyone else looking for jqGrid add/insert examples I hope this one helps out.
Upvotes: 0