Can anyone help me out to add or update CSS classes and HTML in PagedList.MVC
This is my Index.cshtml
<span>Page</span> @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) <Span>of</Span> @Model.PageCount
@Html.PagedListPager(Model, page => Url.Action("Index", new { page, currentFilter = ViewBag.CurrentFilter }))
When I have inspected in browser I got below Html
<div class="pagination-container">
<ul class="pagination">
<li class="active"><a>1</a></li>
<li><a href="/abc/?page=2">2</a></li>
<li class="PagedList-skipToNext"><a href="/abc/?page=2" rel="next">»</a></li>
</ul>
</div>
Instead of above HTML I need this HTML
<div>
<ul class="pagination">
<li class="page-item"><a class="page-link" href="#">Previous</a></li>
<li class="page-item"><a class="page-link" href="#">1</a></li>
<li class="page-item"><a class="page-link" href="#">2</a></li>
<li class="page-item"><a class="page-link" href="#">3</a></li>
<li class="page-item"><a class="page-link" href="#">Next</a></li>
</ul>
</div>
PagedList. mvc is a package for paging and sorting for ASP.NET MVC. PagedList package installs a PagedList collection type and extension methods for IQueryable and IEnumerable collections. Table Data.
NET application to insert page pagination, first need to install Paged List and PagedList. MVC from the NuGet packages for the project. Then I have included sample method which return the list of books from database. And I included the Page pagination to show 4 items in each page.
If you use X.PagedList (which is a fork of troygoode's PagedList), you can make use of the PageClasses
option in PagedListRenderOptions
.
Here's how you would achieve the classes that Bootstrap 4 is looking for:
@Html.PagedListPager((IPagedList)ViewBag.OnePageOfProducts, page =>
Url.Action("Index", new { page = page }),
new PagedListRenderOptions {
LiElementClasses = new string[] { "page-item" },
PageClasses = new string[] { "page-link" }
})
See documentation here.
This way works for me:
first import on top of the page: @using X.PagedList.Mvc.Core.Common;
and than use like this:
@Html.PagedListPager(Model, page => Url.Action("Index", new { page }), new PagedListRenderOptions
{
DisplayLinkToIndividualPages = true,
DisplayPageCountAndCurrentLocation = false,
MaximumPageNumbersToDisplay = 10,
LiElementClasses = new string[] { "page-item" },
PageClasses = new string[] { "page-link" },
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With