Mitc.Support.Pagination 1.0.9
Mitc.Support.Pagination
A return type for paginated API responses, with optional support for generating pagination UI controls.
Paginating a Query
Use the Paginated extension on IQueryable<T> with a PaginationInfo to get a paginated result:
var info = new PaginationInfo { PageNumber = 1, PageSize = 25 };
Paginated<Product[]> result = dbContext.Products.Paginated(info);
With a projection:
Paginated<ProductDto[]> result = dbContext.Products.Paginated(info, p => new ProductDto(p));
Paginated Result
Paginated<T> carries the data along with pagination metadata:
result.Data // T — the page of results
result.PageNumber // current page
result.PageSize // items per page
result.TotalPages // total number of pages
result.TotalRecords // total number of items across all pages
result.FirstPage // always 1
result.LastPage // same as TotalPages
result.NextPage // next page (clamped to last page)
result.PreviousPage // previous page (clamped to first page)
result.HasNextPage // true when not on the last page
result.HasPreviousPage // true when not on the first page
Pagination Controls
Generate a sequence of UI controls for rendering a pager with ToPaginationControls:
IEnumerable<PaginationControl> controls = result.ToPaginationControls();
Each PaginationControl has:
Type —
First,Previous,Page,Ellipsis,Next, orLastQuerySegment — a query string fragment (e.g.
PageNumber=3&PageSize=25) for building linksText — default display text for each control type:
Type Default Text First «Previous ‹Page page number Ellipsis …Next ›Last »IsCurrent —
truewhen the control's target is the page already being viewed
Example output (page 5 of 10, radius 2)
«, ‹, …, 3, 4, 5, 6, 7, …, ›, »
Customizing the window radius
The radius parameter controls how many page numbers appear on each side of the current page:
var controls = result.ToPaginationControls(radius: 3);
Excluding control types
Pass an array of PaginationControlType values to omit specific control types:
var controls = result.ToPaginationControls(exclude: new[] { PaginationControlType.Ellipsis });
Query Segments
PaginationInfo.ToQuerySegment generates a query string fragment from a page number and page size:
string qs = PaginationInfo.ToQuerySegment(page: 3, pageSize: 25);
// "PageNumber=3&PageSize=25"
Target Frameworks
netstandard2.0
Showing the top 20 packages that depend on Mitc.Support.Pagination.
| Packages | Downloads |
|---|---|
|
Mitc.Support.Pagination.EntityFramework
Package Description
|
0 |
|
Mitc.Support.Pagination.EntityFramework
Package Description
|
10 |
.NET Standard 2.0
- Mitc.Support.Require (>= 1.0.0)