It is a plugin that allows us to quickly paginate while using Entity framework.
ToPagedListAsync,ToPagedList
PM> Install-Package ENPAGER
PM> Standart Paging
var totalCount = await await _context.Where(x => x.Name.Contains('Enis')).CountAsync();
var items = await await _context
.Customers
.Where(x => x.Name.Contains('Enis'))
.Skip((pageIndex - 1) * pageSize)
.Take(pageSize)
.ToListAsync();
int totalPages = (int) Math.Ceiling((double) TotalCount / PageSize);
bool hasPreviousPage = pageIndex > 1;
bool hasNextPage = pageIndex < totalPages;
var customersPagedList = new {
PageIndex = pageIndex,
PageSize = pageSize,
TotalCount = totalCount,
TotalPages = totalPages,
HasPreviousPage = hasPreviousPage,
HasNextPage = hasNextPage
};
PM> Using ToPagedListAsync
var customersPagedList = await _context
.Customers
.Where(x => x.Name.Contains('Enis'))
.ToPagedListAsync(pageIndex,pageSize);
PM> ViewImport.cshtml
@addTagHelper *, ENPAGER
PM> Using FrontEnd Pager {Using View}.cshtml
<EnPager total-items="Model.customer.TotalCount"
total-pages="Model.customer.TotalPages"
page="Model.customer.PageIndex"
page-size="Model.customer.PageSize"
show-active-link="true"
/>