You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PageListPager无匹配4参数重载求助:分页栏添前后按钮报错

Fixing the "PagedListPager no overload takes 4 arguments" Error

Hey there, let's get that pagination button issue sorted out! The error you're seeing happens because you're passing 4 arguments to @Html.PagedListPager, but there's no overload of that method that accepts that combination of parameters. That third argument (the action name string) is the extra one throwing things off—you don't need to pass it separately because you're already specifying the action in your Url.Action call.

Corrected Code

Here's the adjusted version of your code that should work properly:

@Html.PagedListPager(
    Model,
    pageIndex => Url.Action(ViewContext.RouteData.Values["action"].ToString(), new { pageIndex }),
    new PagedListRenderOptions() 
    { 
        LinkToNextPageFormat = "Next", 
        LinkToPreviousPageFormat = "Previous", 
        DisplayLinkToNextPage = PagedListDisplayMode.IfNeeded, 
        DisplayLinkToPreviousPage = PagedListDisplayMode.IfNeeded 
    }
)

What Changed?

I removed the third argument (ViewContext.RouteData.Values["action"].ToString()) because:

  • The PagedListPager method doesn't have an overload that takes an action name as the third parameter.
  • You're already dynamically fetching the current action name inside the Url.Action call, which is the right place to handle that logic.

Bonus: Adding Extra Route Parameters

If you need to pass additional values (like search filters, sort criteria) along with the page index, just include them in the anonymous object to preserve those parameters when navigating pages:

pageIndex => Url.Action(
    ViewContext.RouteData.Values["action"].ToString(), 
    new { 
        pageIndex, 
        searchTerm = ViewBag.SearchTerm, 
        sortColumn = ViewBag.SortColumn 
    }
)

内容的提问来源于stack exchange,提问作者Breathing

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 07:36:57