public IActionResult Search([FromQuery] string Search, [FromQuery] int?page) { var pageNumber = page == null || page <= 0 ? 1 : page.Value; if (String.IsNullOrWhiteSpace(Search)) { return(RedirectToAction(nameof(Index))); } var photos = _photoRepo.SearchPhotos(Search) .Select(photo => new PhotosIndexViewModel { Id = photo.Id, Name = photo.Name, Description = photo.Description, Category = photo.Category, PhotoUrl = photo.PhotoUrl, DateCreated = photo.DateCreated.ToLongDateString(), FaceBookLink = photo.FaceBookLink, InstagramLink = photo.InstagramLink, TwitterLink = photo.TwitterLink }); var model = new PhotosListViewModel { Search = Search, Photos = new PagedList <PhotosIndexViewModel>(photos, pageNumber, 12) }; return(View(model)); }