PagedList.Core.Mvc PagedListPager Html extension i

2019-07-15 08:18发布

问题:

It seems like the PagedList.Core does not contain the extension method for Html helper, so I cannot use the code below:

@Html.PagedListPager(Model, page => Url.Action("Index", new { page }), PagedListRenderOptions.MinimalWithItemCountText)

I was able to successfully implement the paging in previous version of MVC, but it does not work in ASP.Net Core. Below I have attached IL Dasm reference. Am I missing something, or is there any other way to implement that?

PagedList.Mvc:

PagedList.Core.Mvc:

回答1:

I should follow the Instructions of the new version, it is a little different from previous version. I was able to implement the paging with the following code changes:

Startup.cs:

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddSingleton<IActionContextAccessor, ActionContextAccessor>();
    }

_ViewImports.cshtml:

@addTagHelper *, PagedList.Core.Mvc

And finally to use it, we don't use Html tag helper anymore in .Net Core:

<pager class="pager-container" list="@Model" options="@PagedListRenderOptions.TwitterBootstrapPager" asp-action="Index" asp-controller="ControllerName" />


回答2:

Include X.PagedList.Mvc.Core nuget in your project. Then add this to your view:

@using X.PagedList.Mvc.Core

Then this should work:

@Html.PagedListPager(Model, page => Url.Action("Index", new { page }))