public static string PagedListPager <T>(IPagedList <T> paged, Func <int, string> generatePageUrl, PagedListRenderOptions options, int index, int pagerSize) { if (paged.PageCount == 1) { return(""); } var listItemLinks = new StringBuilder(); if (options.DisplayLinkToFirstPage) { var first = First(paged, generatePageUrl, options.LinkToFirstPageFormat); if (first != null) { listItemLinks.Append(first); } } if (options.DisplayLinkToPreviousPage) { var pre = Previous(paged, generatePageUrl, options.LinkToPreviousPageFormat); if (pre != null) { listItemLinks.Append(pre); } } if (options.DisplayLinkToIndividualPages) { var max = pagerSize; var half = (int)Math.Round((decimal)max / 2, 0, MidpointRounding.ToEven); var start = 0; var stop = max; if (paged.PageIndex > half) { start = paged.PageIndex - half; stop = start + max; } if (stop > paged.PageCount) { stop = paged.PageCount; start = stop - max; } if (start < 0) { start = 0; } for (var i = start; i < stop; i++) { listItemLinks.Append(Page(i, paged, generatePageUrl, options.LinkToIndividualPageFormat)); } } if (options.DisplayLinkToNextPage) { var next = Next(paged, generatePageUrl, options.LinkToNextPageFormat); if (next != null) { listItemLinks.Append(next); } } if (options.DisplayLinkToLastPage) { var last = Last(paged, generatePageUrl, options.LinkToLastPageFormat); if (last != null) { listItemLinks.Append(last); } } var outerDiv = new TagBuilder("div"); outerDiv.AddCssClass("pagination pagination-sm"); outerDiv.InnerHtml.SetHtmlContent("<ul>" + listItemLinks + "</ul>"); return(outerDiv.ToString()); }
public static string PagedListPager2(this IHtmlHelper html, IPagedList list, Func <int, string> generatePageUrl, PagedListRenderOptions options, int currentPageSize, string pageSizeUrl, List <int> itemCountList) { var listItemLinks = new StringBuilder(); var result = Result(list); if (options.DisplayLinkToFirstPage) { var first = First(list, generatePageUrl, options.LinkToFirstPageFormat); if (first != null) { listItemLinks.Append(first.GetString()); } } if (options.DisplayLinkToPreviousPage) { var pre = Previous(list, generatePageUrl, options.LinkToPreviousPageFormat); if (pre != null) { listItemLinks.Append(pre.GetString()); } } if (options.DisplayLinkToIndividualPages) { var max = 10; var half = (int)Math.Round((decimal)max / 2, 0, MidpointRounding.ToEven); var start = 0; var stop = max; if (list.PageIndex > half) { start = list.PageIndex - half; stop = start + max; } if (stop > list.PageCount) { stop = list.PageCount; start = stop - max; } if (start < 0) { start = 0; } for (var i = start; i < stop; i++) { listItemLinks.Append(Page(i, list, generatePageUrl, options.LinkToIndividualPageFormat).GetString()); } } if (options.DisplayLinkToNextPage) { var next = Next(list, generatePageUrl, options.LinkToNextPageFormat); if (next != null) { listItemLinks.Append(next.GetString()); } } if (options.DisplayLinkToLastPage) { var last = Last(list, generatePageUrl, options.LinkToLastPageFormat); if (last != null) { listItemLinks.Append(last.GetString()); } } var pagerDiv = new TagBuilder("div"); pagerDiv.AddCssClass("row"); pagerDiv.GenerateId("divPager", ""); var divLeft = new TagBuilder("div"); divLeft.AddCssClass("col-md-3 col-sm-12"); var divInfo = new TagBuilder("div"); divInfo.AddCssClass("info"); divInfo.InnerHtml.SetHtmlContent(result.GetString() + ", " + PageSizeCombo(options.PageSizeText, currentPageSize, pageSizeUrl, itemCountList).GetString()); divLeft.InnerHtml.SetHtmlContent(divInfo.GetString()); var divRight = new TagBuilder("div"); divRight.AddCssClass("col-md-9 col-sm-12"); var divPager = new TagBuilder("div"); divPager.AddCssClass("paginate"); var outerDiv = new TagBuilder("ul"); outerDiv.AddCssClass("pagination pagination-sm"); outerDiv.InnerHtml.SetHtmlContent(listItemLinks.ToString()); divPager.InnerHtml.SetHtmlContent(outerDiv.GetString()); divRight.InnerHtml.SetHtmlContent(divPager.GetString()); pagerDiv.InnerHtml.SetHtmlContent(divLeft.GetString() + divRight.GetString()); return(pagerDiv.GetString()); }