public JsonResult GetCompanies(string sidx, string sort, int page, int rows) { sort = (sort == null) ? "" : sort; int pageIndex = Convert.ToInt32(page) - 1; int pageSize = rows; AdminUsers obj = new AdminUsers(); var _CompaniesData = obj.GetCompanies(); int totalRecords = _CompaniesData.Count(); var totalPages = (int)Math.Ceiling((float)totalRecords / (float)rows); if (sort.ToUpper() == "DESC") { _CompaniesData = _CompaniesData.OrderByDescending(t => t.ServiceFirstCompanyID).ToList(); _CompaniesData = _CompaniesData.Skip(pageIndex * pageSize).Take(pageSize).ToList(); } else { _CompaniesData = _CompaniesData.OrderBy(t => t.ServiceFirstCompanyID).ToList(); _CompaniesData = _CompaniesData.Skip(pageIndex * pageSize).Take(pageSize).ToList(); } var jsonData = new { total = totalPages, page, records = totalRecords, rows = _CompaniesData }; return(Json(jsonData, JsonRequestBehavior.AllowGet)); }