public ActionResult LoadAddressBookData() { try { var draw = Request.Form.GetValues("draw").FirstOrDefault(); var start = Request.Form.GetValues("start").FirstOrDefault(); var length = Request.Form.GetValues("length").FirstOrDefault(); var sortColumn = Request.Form.GetValues("columns[" + Request.Form.GetValues("order[0][column]").FirstOrDefault() + "][name]").FirstOrDefault(); var sortColumnDir = Request.Form.GetValues("order[0][dir]").FirstOrDefault(); var searchValue = Request.Form.GetValues("search[value]").FirstOrDefault(); //Paging Size (10,20,50,100) int pageSize = length != null?Convert.ToInt32(length) : 0; int skip = start != null?Convert.ToInt32(start) : 0; int recordsTotal = 0; // Getting all address book data DbData objDB = new DbData(); //calling class DBdata var addressBookData = objDB.PopulateAddressBookData(); //Sorting //if (!(string.IsNullOrEmpty(sortColumn) && string.IsNullOrEmpty(sortColumnDir))) //{ // addressBookData = addressBookData.OrderBy(sortColumn + " " + sortColumnDir); //} //Search if (!string.IsNullOrEmpty(searchValue)) { addressBookData = addressBookData.Where(m => m.Name == searchValue); } //total number of rows count recordsTotal = addressBookData.Count(); //Paging var data = addressBookData.Skip(skip).Take(pageSize).ToList(); //Returning Json Data return(Json(new { draw = draw, recordsFiltered = recordsTotal, recordsTotal = recordsTotal, data = data })); } catch (Exception) { throw; } }