public JsonResult GetOptimization(PagingOptions options, Int32 range, int type, int id, String KeyName) { //paging parameter var start = options.Start; //sorting parameter var sortColumn = options.ColumnName; var sortColumnDir = options.Direction ? "descending" : "ascending"; //filter parameter var searchValue = options.SearchName; int skip = start; int recordsTotal = 0; var OptimizedCamps = new List <Log>(); if (sortColumnDir == "ascending") { OptimizedCamps = dashboardData.GetOptimization(type, id, KeyName, 1, SessionData.UserID); } else { OptimizedCamps = dashboardData.GetOptimization(type, id, KeyName, 0, SessionData.UserID); } //Database query var v = from a in OptimizedCamps select a; if (!string.IsNullOrEmpty(searchValue)) { v = v.Where(a => a.KeywordName.ToLower().Contains(searchValue.ToLower()) ); } //sort if (sortColumn == "ModifiedOn") { recordsTotal = v.Count(); int pageSize = recordsTotal; OptimizedCamps = v.Skip(skip).Take(pageSize).ToList(); } else { if (!(string.IsNullOrEmpty(sortColumn) && string.IsNullOrEmpty(sortColumnDir))) { v = SkipZeroOptimize(sortColumn, v); //for make sort simpler we will add Syste.Linq.Dynamic reference v = v.OrderBy(sortColumn + " " + sortColumnDir); recordsTotal = v.Count(); int pageSize = recordsTotal; OptimizedCamps = v.Skip(skip).Take(pageSize).ToList(); } } return(Json(new { recordsTotal = recordsTotal, data = OptimizedCamps })); }