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

时间:2015-05-13 12:00:49

标签: c# asp.net-mvc pagedlist

我正在使用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。我如何实现这一目标?

3 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:2)

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

    @{
    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 
   )

答案 2 :(得分:0)

从查看文档看起来好像现在可以有多个选项。

    @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