public async Task <ActionResult> Index(string currentFilter, int?page, string searchString = null, string sortOrder = null) { ViewBag.CurrentSort = sortOrder; ViewBag.NameSortParm = sortOrder == "Name" ? "name_desc" : "Name"; ViewBag.NameSortParm = sortOrder == "StartTime" ? "startTime_desc" : "StartTime"; ViewBag.NameSortParm = sortOrder == "EndTime" ? "endTime_desc" : "EndTime"; if (searchString != null) { page = 1; } else { searchString = currentFilter; } ViewBag.CurrentFilter = searchString; AssignmentParameters.PageSize = 5; AssignmentParameters.PageNumber = (page ?? 1); AssignmentParameters.SearchString = searchString; AssignmentParameters.SortOrder = sortOrder; AssignmentParameters.Paged = true; var assignmentPagedList = await Service.GetAllPagedListAsync(AssignmentParameters); var viewModel = Mapper.Map <IEnumerable <AssignmentIndexViewModel> >(assignmentPagedList); var pagedViewModel = new StaticPagedList <AssignmentIndexViewModel>(viewModel, assignmentPagedList.GetMetaData()); return(View(pagedViewModel)); }