public async Task <PartialViewResult> _IndexGrid(string search, string sort = "", string order = "", long?page = 1) { //Permisos Permisos(ControllerContext.RouteData.Values["controller"].ToString()); var listado = new List <FichasIngresosInfo>(); ViewBag.NombreListado = Etiquetas.TituloGridFichaIngrso; page = page > 0 ? page - 1 : page; int totalPaginas = 1; try { var query = (HttpContext.Request.Params.Get("QUERY_STRING") ?? "").ToString(); var dynamicQueryString = GetQueryString(query); var whereClause = BuildWhereDynamicClause(dynamicQueryString); //Siempre y cuando no haya filtros definidos en el Grid if (string.IsNullOrEmpty(whereClause)) { if (!string.IsNullOrEmpty(sort) && !string.IsNullOrEmpty(order)) { listado = FichaIngresoDAL.ListadoFichaIngreso(page.Value).OrderBy(sort + " " + order).ToList(); } else { listado = FichaIngresoDAL.ListadoFichaIngreso(page.Value).ToList(); } } search = !string.IsNullOrEmpty(search) ? search.Trim() : ""; if (!string.IsNullOrEmpty(search))//filter { listado = FichaIngresoDAL.ListadoFichaIngreso(null, search); } if (!string.IsNullOrEmpty(whereClause) && string.IsNullOrEmpty(search)) { if (!string.IsNullOrEmpty(sort) && !string.IsNullOrEmpty(order)) { listado = FichaIngresoDAL.ListadoFichaIngreso(null, null, whereClause).OrderBy(sort + " " + order).ToList(); } else { listado = FichaIngresoDAL.ListadoFichaIngreso(null, null, whereClause); } } else { if (string.IsNullOrEmpty(search)) { totalPaginas = FichaIngresoDAL.ObtenerTotalRegistrosListadoFichaIngreso(); } } ViewBag.TotalPaginas = totalPaginas; // Only grid query values will be available here. return(PartialView(await Task.Run(() => listado))); } catch (Exception ex) { ViewBag.TotalPaginas = totalPaginas; // Only grid query values will be available here. return(PartialView(await Task.Run(() => listado))); } }