public ActionResult DyGridData(string id, string sord, int page, int rows) {
EmployeeContext context = new EmployeeContext();
int pageIndex = Convert.ToInt32(page) - 1;
int pageSize = rows;
int totalRecords = context.Employees.Count();
int totalPages = (int)Math.Ceiling((float)totalRecords / (float)pageSize);
var employees = context.Employees.OrderBy(p=>p.EmployeeId).Skip(pageIndex * pageSize).Take(pageSize);
var jsonData = new {
total = totalPages,
page,
records = totalRecords,
rows = ( from employee in employees
select new { i=employee.EmployeeId ,
cell = new string[]
{ employee.Name, employee.Age.ToString(),employee.Salary.ToString(),employee.Department,employee.City }
}).ToArray()
};
return Json(jsonData, JsonRequestBehavior.AllowGet);
}
Try to execute the query first by adding ToArray at the end of the statement.
var employees = context.Employees
.OrderBy(p=>p.EmployeeId)
.Skip(pageIndex * pageSize)
.Take(pageSize)
.ToArray(); // Add this.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.