Hello,
I have a strange behavior. The code below worked from a long time but nowI don't know why I didn't change anything, I have an exception. I get employee from my database via Nhibernate, the _model.List have the employee list. I have an exception on the line juste before the return (where I build the array). I format the data to use them in jqGrid.
The exception is : Object reference not set to an instance of an object.
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult ListToGrid(string sidx, string sord, int page, int rows)
{
_model.List = _employeeService.List();
Func<Employee, string> order;
switch (sidx.ToUpper())
{
case "FIRSTNAME": order = x => x.FirstName; break;
case "LASTNAME": order = x => x.LastName; break;
default: order = x => x.Login; break;
}
if (sord.ToUpper() == "ASC")
_model.List = _model.List.OrderBy(order).ToList<Employee>();
else
_model.List = _model.List.OrderByDescending(order).ToList<Employee>();
var data = _model.List.Select(c => new { id = c.Id, cell = new[] { c.Id.ToString(), c.Login.ToString(), c.FirstName, c.LastName, c.IsActive.ToString() } }).ToArray();
return new JsonResult { Data = new { page = page, records = data.Length, rows = data, total = 1 } };
}