【问题标题】:How to have multiple PagedListRenderOptions in PagedList.Mvc?如何在 PagedList.Mvc 中有多个 PagedListRenderOptions?
【发布时间】:2015-05-13 12:00:48
【问题描述】:

我正在使用 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。我如何做到这一点?

【问题讨论】:

    标签: c# asp.net-mvc pagedlist


    【解决方案1】:

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

    【讨论】:

      【解决方案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 
         )
      

      【讨论】:

        【解决方案3】:

        从查看文档看来,现在可以有多种选择。

            @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

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2015-08-03
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多