首页 > 解决方案 > 如何在 asp.net 核心中更改“ReflectionIT.Mvc.Paging”包样式

问题描述

我正在开发一个Asp.net core 2.2项目并使用ReflectionIT.Mvc.Paging包进行分页。一切都很好,但我想在我看来改变分页样式。

这是使用Pager视图组件的代码

    <nav>
        @await this.Component.InvokeAsync("Pager", new { PagingList = this.Model })
    </nav>

这是寻呼图片:

在此处输入图像描述

我想在上面的图片中写FirstAndLast而不是1And15并想更改一些 css 样式。

标签: asp.net-core.net-corepaginationpaging

解决方案


You can also create your own Pager view if you want to. You store it in the folder Views\Shared\Components\Pager :

enter image description here

You can for instance call the AddPaging method which you can use to set the PagingOptions. This allows you to specify which View is used for the Pager ViewComponent , in ConfigureServicesfunction :

// Register ViewComponent using an EmbeddedFileProvider & setting some options
services.AddPaging(options => {
    options.ViewName = "Bootstrap5";
    options.HtmlIndicatorDown = " <span>&darr;</span>";
    options.HtmlIndicatorUp = " <span>&uarr;</span>";
});

Modify the Bootstrap5.cshtml to fit your requirement :

@model  ReflectionIT.Mvc.Paging.IPagingList

@* Fake Boostrap 5 based pager *@

@{
    var start = this.Model.StartPageIndex;
    var stop = this.Model.StopPageIndex;
}

@if (this.Model.PageCount > 1) {
    <ul class="pagination pagination-sm justify-content-end">

        @if (start > 1) {
            <li class="page-item">
                <a href="@Url.Action(Model.Action, Model.GetRouteValueForPage(1))" aria-label="First" class="page-link">
                    <span aria-hidden="true">First</span>
                </a>
            </li>
        }

        @if (this.Model.PageIndex > 1) {
            <li class="page-item">
                <a href="@Url.Action(Model.Action, Model.GetRouteValueForPage(this.Model.PageIndex - 1))" aria-label="Previous" class="page-link">
                    <span aria-hidden="true">&laquo;</span>
                </a>
            </li>
        }

        @for (int i = start; i <= stop; i++) {
            <li class="page-item @((Model.PageIndex == i) ? "active" : null)">
            @if (i == 1)
                {
                    @Html.ActionLink("First", Model.Action, Model.GetRouteValueForPage(i), new { @class = "page-link" })
                }
                else{
                    @Html.ActionLink(i.ToString(), Model.Action, Model.GetRouteValueForPage(i), new { @class = "page-link" })
                }

            </li>
        }

        @if (this.Model.PageIndex < this.Model.PageCount) {
            <li class="page-item">
                <a href="@Url.Action(Model.Action, Model.GetRouteValueForPage(this.Model.PageIndex + 1))" aria-label="Next" class="page-link">
                    <span aria-hidden="true">&raquo;</span>
                </a>
            </li>
        }

        @if (stop < this.Model.PageCount) {
            <li class="page-item">
                <a href="@Url.Action(Model.Action, Model.GetRouteValueForPage(this.Model.PageCount))" aria-label="Last" class="page-link">
                    <span aria-hidden="true">Last</span>
                </a>
            </li>
        }

    </ul>
}

Output :

enter image description here


推荐阅读