Pioneer Pagination is an ASP.Net Core Tag Helper that produces a paginated list which is configured to a desired state.
Pioneer Pagination is available as a NuGet package.
- In your controller, you make a call to
PaginatedMetaService
which returns aPaginatedMetaModel
. - Your
PaginatedMetaModel
is then passed to your view so that the Tag Helper can utilize it. - In your view, you bind the
PaginatedMetaModel
to an attribute and set a route on another attribute. - The Tag Helper generates a paginated list.
For a full working example, clone this repository and run the Pioneer.Pagination.Example project locally.
To install, run the following command from your package manager console:
PM> Install-Package Pioneer.Pagination
In your Startup.cs class, add PaginatedMetaService
into your dependency injection container.
public void ConfigureServices(IServiceCollection services)
{
services.AddTransient<IPaginatedMetaService, PaginatedMetaService>();
}
In your controller, add a reference to the IPaginatedMetaService
interface and set it through dependency injection.
public class BlogController : Controller
{
private readonly IPaginatedMetaService _paginatedMetaService;
public BlogController(IPaginatedMetaService paginatedMetaService)
{
_paginatedMetaService = paginatedMetaService;
}
}
From your controller, bind the PaginatedMetaModel
to your ViewBag
.
public ActionResult Index(int page = 1)
{
// Typically obtained from a service/repository
var totalNumberInCollection = 100;
// Typically obtained from configuration
var itemsPerPage = 5;
ViewBag.PaginatedMeta = _paginatedMetaService.GetMetaData(totalNumberInCollection, page, itemsPerPage);
return View("Blog", post);
}
<pioneer-pagination info="@ViewBag.PaginatedMeta" route="/blog"></pioneer-pagination>
- previous-page-text
- default = next
- previous-page-text
- default = previous
<pioneer-pagination info="@ViewBag.PaginatedMeta" route="/blog" previous-page-text="hey" next-page-text="you"></pioneer-pagination>
The markup this produces is based on Foundation Pagination. This leaves you one of three options.
- Use Foundation and it will work out of the box.
- Map the classes to Bootstrap stylings.
- Use the starting CSS or sass files provided in the example.
The services will clamp out of range indexes passed to _paginatedMetaService.GetMetaData
. If you pass a current page value < 1, it will be clamped to 1.
If you pass a current page value > then the collectionSize \ itemsPerPage
, it will get clamped to the last valid page.
Because the aggragation of data is handled independetly of the actual tag helper, you will need to insure you are clamping the requests coming from the user in the same manner.
- Migrate to .net standard 2.1
- Migrate example to .net core 3.1
- Security updates.
- Account for out of range request for a page by clamping them.
- Add configuration for previous and next verbiage - ryn0
- Migarted to .NET Standard 2.x
- Migarted example project to ASP.NET Core 2.x
- Fixed Next button not being displayed
- Next should be displayed up until last page.
- Added supported UTs.
- Upgrade to LTS 1.0.3
- Fixed previous and next button indexing
- Supporting UTs.