I'm learning ASP.NET Core Razor Pages with Entity Framework, and I want to implement pagination with my table. I have checked this tutorial:
https://learn.microsoft.com/en-us/aspnet/core/data/ef-rp/sort-filter-page?view=aspnetcore-2.1
but it only supports previous and next pages, with no specific page options.
All the solutions I've found to date are MVC implementations, but I'm using Razor Pages; there's no controller in my project.
This is the effect what I want to implement
This is my .cshtml page code:
<form method="get" asp-page="./Index">
<nav aria-label="Page navigation">
<ul class="pagination">
<li>
<a href="#" aria-label="Previous">
<span aria-hidden="true">«</span>
</a>
</li>
@{
var totalPages = Model.Products.Count % 2 == 0 ? Model.Products.Count / 2 : Model.Products.Count / 2 + 1;
}
@for (int i = 1; i <= totalPages; i++)
{
<li><a asp-page="./Index" asp-route-id="@i">@i</a></li>
}
<li>
<a href="#" aria-label="Next">
<span aria-hidden="true">»</span>
</a>
</li>
</ul>
</nav>
</form>
And my cshtml.cs code-behind:
public async Task OnGetAsync(string sortOrder, string searchString, string shopString, string statusString, int page)
{}