From 4cd0194d670a626b13a773e42e4f2e899b3f429f Mon Sep 17 00:00:00 2001 From: Andrew Date: Tue, 14 Feb 2023 11:41:54 +0200 Subject: [PATCH] Update example. Fix #227 --- .../Views/Bootstrap41/_NameListPartial.cshtml | 18 +++++++++++++++++- src/X.PagedList.Mvc.Core/Common/HtmlHelper.cs | 5 ++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/examples/X.PagedList.Mvc.Example.Core/Views/Bootstrap41/_NameListPartial.cshtml b/examples/X.PagedList.Mvc.Example.Core/Views/Bootstrap41/_NameListPartial.cshtml index 20ee8f66..cc22ab84 100644 --- a/examples/X.PagedList.Mvc.Example.Core/Views/Bootstrap41/_NameListPartial.cshtml +++ b/examples/X.PagedList.Mvc.Example.Core/Views/Bootstrap41/_NameListPartial.cshtml @@ -15,4 +15,20 @@ } -@Html.PagedListPager((IPagedList)ViewBag.Names, page => Url.Action("GetOnePageOfNames", new { page }), PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing(new PagedListRenderOptions { MaximumPageNumbersToDisplay = 5, DisplayPageCountAndCurrentLocation = true, UlElementClasses = new[] { "pagination" }, ContainerDivClasses = new[] { "pagination-container" } }, new AjaxOptions() { HttpMethod = "GET", UpdateTargetId = "nameListContainer" })) +@Html.PagedListPager( + (IPagedList)ViewBag.Names, + page => Url.Action("GetOnePageOfNames", new { page }), + PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing( + new PagedListRenderOptions + { + MaximumPageNumbersToDisplay = 5, + DisplayPageCountAndCurrentLocation = true, + UlElementClasses = new[] { "pagination" }, + ContainerDivClasses = new[] { "pagination-container" } + }, + new AjaxOptions() + { + HttpMethod = "GET", + UpdateTargetId = "nameListContainer" + }) + ) diff --git a/src/X.PagedList.Mvc.Core/Common/HtmlHelper.cs b/src/X.PagedList.Mvc.Core/Common/HtmlHelper.cs index 6494970a..3d131e42 100644 --- a/src/X.PagedList.Mvc.Core/Common/HtmlHelper.cs +++ b/src/X.PagedList.Mvc.Core/Common/HtmlHelper.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Collections.Immutable; using System.Linq; using System.Text; @@ -270,8 +271,10 @@ private ITagBuilder NextEllipsis(IPagedList list, Func generatePage #endregion Private methods - public string PagedListPager(IPagedList list, Func generatePageUrl, PagedListRenderOptions options) + public string PagedListPager(IPagedList pagedList, Func generatePageUrl, PagedListRenderOptions options) { + var list = pagedList ?? new StaticPagedList(ImmutableList.Empty, 1, 10, 0); + if (options.Display == PagedListDisplayMode.Never || (options.Display == PagedListDisplayMode.IfNeeded && list.PageCount <= 1)) { return null;