public ActionResult ClientStatuses_getItems() { var parameters = AjaxModel.GetParameters(HttpContext); var mng = new CRMManager(); var items = mng.GetClientStatuses(); var res = items.Select(item => new crm_clientStatuses { id = item.id, name = item.name, code = item.code, color = item.color, state = item.state }).AsQueryable(); var sorts = parameters.sort.Split(",".ToArray(), StringSplitOptions.RemoveEmptyEntries); var directions = parameters.direction.Split(",".ToArray(), StringSplitOptions.RemoveEmptyEntries); var sort1 = sorts.Length > 0 ? sorts[0] : ""; var direction1 = directions.Length > 0 ? directions[0] : ""; switch (sort1) { case "name": if (direction1 == "up") res = res.OrderBy(x => x.name); else res = res.OrderByDescending(x => x.name); break; case "code": if (direction1 == "up") res = res.OrderBy(x => x.code); else res = res.OrderByDescending(x => x.code); break; case "color": if (direction1 == "up") res = res.OrderBy(x => x.color); else res = res.OrderByDescending(x => x.color); break; case "state": if (direction1 == "up") res = res.OrderBy(x => x.state); else res = res.OrderByDescending(x => x.state); break; default: if (direction1 == "up") res = res.OrderBy(x => x.name); else res = res.OrderByDescending(x => x.name); break; } var total = res.Count(); var res2 = res.Skip(parameters.pageSize * (parameters.page - 1)).Take(parameters.pageSize).ToList(); return Json(new { items = res2.Select(x => new { x.id, x.name, x.code, x.state, x.color, }), total = items.Count },JsonRequestBehavior.AllowGet); }