gpt4 book ai didi

asp.net-core - 如何在asp.net core中更改 `ReflectionIT.Mvc.Paging`包样式

转载 作者:行者123 更新时间:2023-12-02 03:13:22 24 4
gpt4 key购买 nike

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

这是使用 Pager View 组件的代码

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

这是分页图片:

enter image description here

我想在上图中写 FirstLast 而不是 115 并希望更改一些CSS样式。

最佳答案

如果您愿意,您还可以创建自己的寻呼机 View 。您将其存储在文件夹 Views\Shared\Components\Pager 中:

enter image description here

例如,您可以调用 AddPaging 方法,用它来设置 PagingOptions。这允许您在 ConfigureServices 函数中指定用于 Pager ViewComponent 的 View :

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

修改Bootstrap5.cshtml以满足您的要求:

@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>
}

输出:

enter image description here

关于asp.net-core - 如何在asp.net core中更改 `ReflectionIT.Mvc.Paging`包样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56888101/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com