How to use X.PagedList.Mvc
with Core
and Bootstrap 4.0
, and thus create a full automatic page.
How to use X.PagedList.Mvc
with Core
and Bootstrap 4.0
, and thus create a full automatic page.
Today I come to bring a way to use X.PagedList.Mvc
with Core
and Bootstrap 4.0
:
First we have to download X.PagedList.Mvc.Core via NuGet.
In VIEW
We will use:
@using X.PagedList.Mvc.Core
@model X.PagedList.StaticPagedList<"Seu Model">
And here's the trick:
<div>
<div style="float: right">
Página @(Model.PageCount < Model.PageNumber ? 0 : Model.PageNumber) de @Model.PageCount
</div>
<div class="justify-content-center">
@Html.PagedListPager(Model, pagina => Url.Action("Index", new { search = ViewBag.Busca, pagina }), new PagedListRenderOptions { FunctionToTransformEachPageLink = (liTag, aTag) => { aTag.Attributes.Add("class", "page-link".ToString()); return aTag; }, LiElementClasses = new[] { "page-item" }, UlElementClasses = new[] { "pagination justify-content-center" } })
</div>
</div>
In this way @Html.PagedListPager
will create the new classes that are required for Bootstrap 4.0.
And to finish, it is only to return the model with all the necessary data to View through Controller
.
More and a hug.