public ActionResult PostPage(int page = 1) { int pageSize = 5; var posts = _postService.Posts(page - 1, pageSize); var postsModel = _mapper.Map <IEnumerable <PostViewModel> >(posts); var totalPosts = _postService.TotalPosts(); PaheInformation pageInfo = new PaheInformation { PageNo = page, PageSize = pageSize, TotalItems = totalPosts }; var listViewModel = new PostsPaginationModel() { Posts = postsModel, PageInfo = pageInfo }; return(View(listViewModel)); }
public static MvcHtmlString PageLinks(this HtmlHelper html, PaheInformation pageInfo, Func <int, string> pageUrl) { StringBuilder link = new StringBuilder(); for (int i = 1; i <= pageInfo.TotalPages; i++) { TagBuilder tag = new TagBuilder("a"); tag.MergeAttribute("href", pageUrl(i)); tag.InnerHtml = i.ToString(); if (i == pageInfo.PageNo) { tag.AddCssClass("selected"); tag.AddCssClass("btn-primary"); } tag.AddCssClass("btn btm-default"); link.Append(tag.ToString()); } return(MvcHtmlString.Create(link.ToString())); }