如何在PagedList.MVC中自定义设计?

时间:2018-04-12 11:39:53

标签: c# asp.net asp.net-mvc asp.net-mvc-4

您好,任何人都可以帮我在PagedList.MVC中添加或更新Css类和Html

这是我的 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 }))

当我在浏览器中检查时,我得到了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>

而不是上面的Html我需要这个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>

2 个答案:

答案 0 :(得分:2)

如果使用X.PagedList(这是troygoode的PagedList的分支),则可以使用PageClasses中的PagedListRenderOptions选项。

这是实现Bootstrap 4寻找的类的方法:

@Html.PagedListPager((IPagedList)ViewBag.OnePageOfProducts, page => 
    Url.Action("Index", new { page = page }), 
    new PagedListRenderOptions {
        LiElementClasses = new string[] { "page-item" },
        PageClasses = new string[] { "page-link" }
})

https://www.sklein-medien.de/en/tutorials/detail/translating-forms-in-the-typo3-form-framework/

答案 1 :(得分:1)

这种方式对我有用:

首次导入页面顶部: @using X.PagedList.Mvc.Core.Common;

,然后像这样使用

   @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" },
                   
                    })