public JsonResult GetProducts(int limit, int offset, string departmentname) { List <ProductViewModel> lstRes = null; if (!string.IsNullOrEmpty(departmentname)) { lstRes = BProduct.SearchBysql(departmentname); } else { lstRes = BProduct.SearchAll(); } var total = lstRes.Count; var rows = lstRes.Skip(offset).Take(limit).ToList(); return(Json(new { total = total, rows = rows }, JsonRequestBehavior.AllowGet)); }