public ActionResult Search(string query, int?page) { int pageing = 1; if (page.HasValue) { pageing = page.Value; } var from = (pageing - 1) * _config.PhotosPerPage + 1; var to = pageing * _config.PhotosPerPage; ViewBag.Query = query; ViewBag.Page = pageing; IList <Photo> photos = _photoManager.Search(from, to, query); return(View(PhotoListToGalleryModel(photos))); }