.net core 使用 PagedList.Core.Mvc

2021-08-18

1  dotnet add package PagedList.Core.Mvc


2  在 ConfigureServices 里添加

   services.AddSingleton<IActionContextAccessor, ActionContextAccessor>();

   IActionContextAccessor 没引用,要引用

   using Microsoft.AspNetCore.Mvc.Infrastructure;


3 Views/_ViewImports.cshtml

@addTagHelper *, PagedList.Core.Mvc


4  使用

@{

            var PagedListRenderOptions = PageListOptions.GetPagedListRenderOptions;

            var RouteData = new Dictionary<string, string>();

            RouteData.Add("searchString", Model.Search);

            RouteData.Add("sortBy", Model.SortBy);

 }

<pager list="@Model.blogs" options="@PagedListRenderOptions" asp-controller="Blog"

               asp-action="Index" asp-all-route-data="RouteData" />


联系信息

QQ:1827566828
Email: 1827566828@qq.com
Web: https://www.yynet.wang

留言