I am new to jqgrid, I learned from here and tried to implement this in my project. But I am getting the error:
Quote: The parameters dictionary contains a null entry for parameter 'page' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.JsonResult DisplayUsers(System.String, System.String, Int32, Int32)' in 'MyProject.Controllers.AppUserController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Exception Details: System.ArgumentException: The parameters dictionary contains a null entry for parameter 'page' of non-nullable type 'System.Int32' for method 'System.Web.Mvc.JsonResult DisplayUsers(System.String, System.String, Int32, Int32)' in 'MyProject.Controllers.AppUserController'. An optional parameter must be a reference type, a nullable type, or be declared as an optional parameter.
Parameter name: parameters
My controller class:
public class AppUserController : Controller
{
MyProjectContext db = new MyProjectContext();
public JsonResult DisplayUsers(string sidx, string sord, int page, int rows)
{
int pageIndex = Convert.ToInt32(page) - 1;
int pageSize = rows;
var displayUsers = db.app_user.Select(
a => new
{
a.id,
a.username,
a.password,
a.user_role,
a.date_of_register,
a.is_active
});
int totalRecords = displayUsers.Count();
var totalPages = (int)Math.Ceiling((float)totalRecords / (float)rows);
if (sord.ToUpper() == "DESC")
{
displayUsers = displayUsers.OrderByDescending(s => s.username);
displayUsers = displayUsers.Skip(pageIndex * pageSize).Take(pageSize);
}
else
{
displayUsers = displayUsers.OrderBy(s => s.username);
displayUsers = displayUsers.Skip(pageIndex * pageSize).Take(pageSize);
}
var jsonData = new
{
total = totalPages,
page,
records = totalRecords,
rows = displayUsers
};
return Json(jsonData, JsonRequestBehavior.AllowGet);
}
}
displayUsers.js
$(function () {
$("#ListGrid").jqGrid({
url: "/AppUser/DisplayUsers",
datatype: 'json',
mtype: 'Get',
colNames: ['Id', 'User Name', 'User Role', 'Date Of Register', 'Status'],
colModel: [
{ key: true, hidden: true, name: 'id', index: 'id', editable: true },
{ key: false, name: 'username', index: 'username', editable: true },
{ key: false, name: 'user_role', index: 'user_role', editable: true },
{ key: false, name: 'date_of_register', index: 'date_of_register', editable: true, formatter: 'date', formatoptions: { newformat: 'd/m/Y' } },
{ key: false, name: 'is_active', index: 'is_active', editable: true, edittype: 'select', editoptions: { value: { 'A': 'Active', 'I': 'InActive' } } }],
pager: jQuery('#pager'),
rowNum: 10,
rowList: [10, 20, 30, 40],
height: '100%',
viewrecords: true,
caption: 'Users',
emptyrecords: 'No records to display',
jsonReader: {
root: "rows",
page: "page",
total: "total",
records: "records",
repeatitems: false,
Id: "0"
}
});
});
Please help me with this.
|