I have my jQuery code like this
$(document).ready(function () {
var lastsel;
$('#jqgProducts').jqGrid({
//url from wich data should be requested
url: '@Url.Action("CompOff")',
//type of data
datatype: 'json',
//url access method type
mtype: 'POST',
//columns names
ondblClickRow: function (id) {
if (id && id !== lastsel) {
jQuery('#list').restoreRow(lastsel);
jQuery('#list').editRow(id, true);
lastsel = id;
}
$('#jqgProducts').editRow(id, true,null, null);
},
editurl: '@Url.Action("CompOffEdit")',
colNames: ['IdNr', 'CompOffDate', 'Description', 'ExpiryDate', 'IsApproved', 'AppliedOn'],
//columns model
colModel: [
{ name: 'Id', index: 'Id', align: 'center', editable: true, hidden: true},
{ name: 'CompOffDate', index: 'CompOffDate', align: 'center', formatter: 'date', formatoptions: { newformat: 'd/m/Y' }, editable: true },
{ name: 'Description', index: 'Description', align: 'center', editable: true, editoptions: { maxlength: 200} },
{ name: 'ExpiryDate', index: 'ExpiryDate', align: 'center', formatter: 'date', formatoptions: { newformat: 'd/m/Y' }, editable: false },
{ name: 'IsApproved', index: 'IsApproved', align: 'center', editable: false },
{ name: 'AppliedOn', index: 'AppliedOn', align: 'center', formatter: 'date', formatoptions: { newformat: 'd/m/Y' }, editable: false }
],
//pager for grid
pager: $('#jqgpProducts'),
//number of rows per page
rowNum: 10,
//initial sorting column
sortname: 'CompOffDate',
//initial sorting direction
sortorder: 'asc',
//we want to display total records count
viewrecords: true,
caption: 'Comp Off Details',
//grid height
height: '100%',
jsonReader: {
root: "rows",
page: "page",
total: "total",
records: "records",
repeatitems: false,
cell: "cell",
id: "id",
userdata: "userdata"
}
});
});
my controller like this
public ActionResult CompOffEdit(int Id,DateTime CompOffDate, string Description)
{
RegisterCompOff r = db.RegisterCompOffs.Where(l=>l.Id==Id).SingleOrDefault();
if (!(r == null))
{
r.CompOffDate = CompOffDate;
r.Description = Description;
db.Entry(r).State = EntityState.Modified;
db.SaveChanges();
return Content("true");
}
else
{
return Content("false");
}
}
when i’m trying to save the edits to db..i get this exception
The parameters dictionary contains a null entry for parameter 'idnr' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.ActionResult CompOffEdit(Int32, System.DateTime, System.String)' in 'AGS.Hrms.Controllers.CompOffController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter. Parameter name: parameters
user can only edit compoff date and description here…and my id field which i’m picking from database is hidden.
can someone help me to rectify this problem
You should rename
idnrparameter of theCompOffEditaction toidor you should rename the defaultidname of the parameter sending to the server during the row editing toidnr. You can useprmNames: {id: "idnr"}option of jqGrid for this.In the same way you should rename
compOffparameter ofCompOffEditaction toCompOffDateandreasontoDescription. Alternatively you can use some class instance, which hasCompOffDateandDescriptionas properties, as the parameter ofCompOffEditaction. In the case theCompOffDateandDescriptionproperties will be initialized with the values from the editing row.