I’m using ASP.Net MVC 4 with a jqGrid, and I’m trying to pass an additional value from the form into the Add and Edit controller methods when jqGrid add/edits a record. My jqGrid looks like this:
$('#jqgRulesSetupVariablesList').jqGrid({
data: JSON.stringify(("#GroupDDL").valueOf()),
contentType: 'application/json; charset=utf-8',
//url from wich data should be requested
url: '@Url.Action("GetRulesSetupVariables")',
ondblClickRow: function (rowid) {
jQuery(this).jqGrid('editGridRow', rowid,
{ url: '@Url.Action("UpdateRulesSetupVariable")', recreateForm: true, closeAfterEdit: true, closeOnEscape: true, reloadAfterSubmit: false });
},
//type of data
datatype: 'json',
//url access method type
mtype: 'POST',
//columns names
colNames: ['ID', 'Name', 'Description', 'Type'],
//columns model
colModel: [
{ name: 'ID', index: 'ID', align: 'left', width: '30px', editable: false, key: true },
{ name: 'Name', index: 'Name', align: 'left', width: '100px', editable: true, edittype: 'text', editoptions: { maxlength: 20 }, editrules: { required: true } },
{ name: 'Description', index: 'Description', align: 'left', width: '260px', editable: true, edittype: 'text', editoptions: { maxlength: 80 }, editrules: { required: true } },
{ name: 'Type', index: 'Type', align: 'left', width: '25px', editable: true, edittype: 'text', editoptions: { maxlength: 1 }, editrules: { required: true } },
],
//pager for grid
pager: $('#jqgRulesSetupVariablesPaging'),
//number of rows per page
rowNum: 10,
//initial sorting column
sortname: 'Name',
//initial sorting direction
sortorder: 'asc',
//we want to display total records count
viewrecords: true,
//grid height
height: 230,
width: 450,
});
$('#jqgRulesSetupVariablesList').jqGrid('navGrid', '#jqgRulesSetupVariablesPaging',
{ add: true, del: false, edit: true, search: false },
// Edit Options
{ url: '@Url.Action("UpdateRulesSetupVariable")', closeAfterEdit: true, closeOnEscape: true, editData: { GroupName: function () { return "ABC"; } } },
// Add Options
{ url: '@Url.Action("InsertRulesSetupVariable")', closeAfterAdd: true, closeOnEscape: true, editData: { GroupName: function () { return "ABC"; } } },
// Delete options
{}
);
My controller is:
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult UpdateRulesSetupVariable(RulesSetupVariableViewModel viewModel, string GroupName)
{
bool updateSuccess = UpdateRulesSetupVariable_Internal(viewModel);
return Json(updateSuccess);
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult InsertRulesSetupVariable(RulesSetupVariableViewModel viewModel, string GroupName)
{
bool updateSuccess = UpdateRulesSetupVariable_Internal(viewModel);
return Json(updateSuccess);
}
and my model:
public class RulesSetupVariableViewModel
{
public int ID { get; set; }
public string Name { get; set; }
public string Description { get; set; }
public string Type { get; set; }
}
The ID, Name, Description and Type are all coming through just fine, but the GroupName is not.
Any ideas what I’m doing wrong here?
I figured it out. Dumb mistake. I was using the doubleClick to edit the row. I modified this line
to this:
This fixed my problem.