public ActionResult List(string category, int page = 1) { int movieCount; category = category.ReplaceDashes(" "); var movies = _moviesRepository.GetPagedData(category, page, MoviesPerPage, out movieCount); var pagingInfo = new PagingInfo { CurrentPage = page, MoviesPerPage = MoviesPerPage, TotalMovies = movieCount }; var viewModel = new MoviesListViewModel { CurrentCategory = category, Movies = movies, Paging = pagingInfo }; return View(viewModel); }
public ActionResult Search(string category, string movie) { var movies = _moviesRepository.SearchMovieByName(category, movie); var pagingInfo = new PagingInfo { CurrentPage = 1, MoviesPerPage = MoviesPerPage, TotalMovies = movies.Count }; var viewModel = new MoviesListViewModel { CurrentCategory = category, Movies = movies, Paging = pagingInfo }; return View("List", viewModel); }
public static HtmlString PageLinks(this HtmlHelper html, PagingInfo pagingInfo, string category) { var result = new StringBuilder(); for (var i = 1; i <= pagingInfo.TotalPages; i++) { var tag = new TagBuilder("a"); string href; if (category == null) { href = "page" + i; } else { href = category + "/page" + i; } tag.MergeAttribute("href", href); tag.InnerHtml = i.ToString(); if (i == pagingInfo.CurrentPage) tag.AddCssClass("selected"); result.AppendLine(tag.ToString()); } return MvcHtmlString.Create(result.ToString()); }