public ActionResult Index(string sortOrder, string searchString) { ViewBag.NameSortParm = String.IsNullOrEmpty(sortOrder) ? "Name desc" : ""; ViewBag.SurnameSortParm = sortOrder == "LastName" ? "LastName desc" : "LastName"; IQueryable <CustomerDTO> customerDTOs = customService.GetCustomersOrder(sortOrder); if (!String.IsNullOrEmpty(searchString)) { customerDTOs = customService.GetCustomersWhere(searchString); } var mapper = new MapperConfiguration(cfg => cfg.CreateMap <CustomerDTO, CustomerViewModel>()).CreateMapper(); var customers = mapper.Map <IEnumerable <CustomerDTO>, List <CustomerViewModel> >(customerDTOs); return(View(customers.AsQueryable())); }