如何在 PagedList.Mvc 中有多个 PagedListRenderOptions?

How to have multiple PagedListRenderOptions in PagedList.Mvc?

我正在使用 C#,我正在使用 PagedList.Mvc 进行 Ajax 调用。我的 cshtml 视图中的代码如下:

@Html.PagedListPager(Model.PagedList, page => Url.Action("SearchTable", "JobOffer", 
    new {
        randomParameters = "BANANAS"
        page = page
    }), PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing(
        new AjaxOptions() { 
            HttpMethod = "GET", 
            UpdateTargetId = "tableAndPaginationDiv" 
        }
    )
)

不过,我也想要PagedListRenderOptions.ClassicPlusFirstAndLast。我该如何实现?

在撰写此答案时,不可能有多个 PagedListRenderOptions。查看文档后,我意识到如果你想要这样的东西,唯一的办法就是自己创建一个自定义选项,大大增加了解决方案的复杂性:

实际上,试试这个怎么样:

    @{
    var pLRO = PagedListRenderOptions.EnableUnobtrusiveAjaxReplacing(
          new AjaxOptions() { 
             HttpMethod = "GET", 
             UpdateTargetId = "tableAndPaginationDiv" 
          }
       );
    //and now here set all the properties you want
    pLRO.DisplayLinkToFirstPage = PagedListDisplayMode.Always;
    pLRO.DisplayLinkToLastPage = PagedListDisplayMode.Always;
    //you can even style the format
    pLRO.LinkToFirstPageFormat = "First";
    pLRO.LinkToLastPageFormat = "Last";
    }
    //the rest of your view
    //...
    //and when you insert the pager just pass the pLRO variable
   @Html.PagedListPager(Model.PagedList, page => Url.Action("SearchTable",     "JobOffer", 
     new {
      randomParameters = "BANANAS"
      page = page
     }), pLRO 
   )

从文档来看,现在似乎可以有多个选项。

    @Html.PagedListPager(
            (IPagedList)ViewBag.OnePageOfProducts,
            page => Url.Action( "Index", 
                                 new { page = page }), 
                                 new PagedListRenderOptions { LinkToFirstPageFormat = "<< Primera", LinkToPreviousPageFormat = "< Anterior", LinkToNextPageFormat = "Siguiente >", LinkToLastPageFormat = "Ultima >>" }
            );

Documentation on GitHub