PageListPager无匹配4参数重载求助:分页栏添前后按钮报错
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
PagedListPagermethod 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.Actioncall, 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

