public ActionResult Index(string sortOrder, string currentFilter, string searchString, int?page) { if (searchString != null) { page = 1; } else { searchString = currentFilter; } var sortfiltaux = new BoardSortFilter { CurrentSort = sortOrder, NameSortParm = string.IsNullOrEmpty(sortOrder) ? BoardVMConstants.NameDesc : string.Empty, DiscriptionSortParm = sortOrder == BoardVMConstants.DiscriptionAsc ? BoardVMConstants.DiscriptionDesc : BoardVMConstants.DiscriptionAsc, CurrentFilter = searchString, }; var elemcount = !String.IsNullOrEmpty(searchString) ? _br.CountConditional(b => b.Name.Contains(searchString)) : _br.Count(); var pageaux = new PaginationAux { ElementsCount = elemcount, PageCount = (int)Math.Ceiling((double)elemcount / PageSize), PageNumber = (page ?? 1), PageSize = PageSize }; IEnumerable <BoardViewModel> boards = SortingFilteringPaging(sortOrder, searchString, pageaux.PageNumber); return(View(new Tuple <IEnumerable <BoardViewModel>, PaginationAux, BoardSortFilter>(boards, pageaux, sortfiltaux))); }