Nothing fancy here, just a convinient pager that works nicely with Bootstrap.
Reference JA.Pagination.MVC5 (Full .NET) or MVC6 (Core) nuget, and with that there will be extension method for HtmlHelper available:
@Html.RenderPager(Model.CurrentPage, Model.TotalPages)
or with overrides:
@Html.RenderPager(Model.CurrentPage, Model.TotalPages,
page => $"?page={page}",
resourceOverrides: resource => { resource.Previous = "«"; resource.Next = "»"; })
This package usage doesn't require any ASP.NET dependencies. In your Razor view make sure you have variables: current page, total page count.
@Html.Raw(Pager.Build(Model.CurrentPage, Model.TotalPages, page => $"?page={page}").Render())
or with overrides:
@Html.Raw(Pager.Build(Model.CurrentPage, Model.TotalPages,
page => $"?page={page}",
resourceOverrides: resource => { resource.Previous = "«"; resource.Next = "»"; })
.Render())
Generated HTML will look like:
<ul class="pagination">
<li><a href="#" >«</a></li>
<li class="active"><a href="?page=1" >1</a></li>
<li><a href="?page=2" >2</a></li>
<li><a href="?page=3" >3</a></li>
<li class="disabled"><span>...</span></li>
<li><a href="?page=20" >20</a></li>
<li><a href="?page=2" >»</a></li>
</ul>
Package names: JA.Pagination, JA.Pagination.MVC5, JA.Pagination.MVC6
https://www.nuget.org/packages/JA.Pagination
https://www.nuget.org/packages/JA.Pagination.MVC5
https://www.nuget.org/packages/JA.Pagination.MVC6
To build sample projects, packages needs to be created first. Build all projects except Samples, and execute Pack.bat from project roots. That will create local nuget repository with packages needed for sample projects.