fix(blog): repair pagination on public and admin interfaces
CI/CD / CI · dotnet build (push) Successful in 35s
CI/CD / Deploy · drsousan (push) Successful in 28s

Public /blog: the handler param was named `page`, which is a reserved
route token in Razor Pages and never binds — so every page silently
showed the same first 10 posts. Renamed the query param to `pg`
([FromQuery(Name="pg")]) and updated the pagination links to match.

Admin: the posts table had no pagination and dumped all rows at once.
Added client-side pagination (10/page) with a prev/next + numbered bar
over the already-loaded posts array.

Verified: public page1=10/page2=4 with zero overlap; admin shows
‹ 1 2 › with correct row counts and active state per page.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
soroush.asadi
2026-06-11 00:23:22 +03:30
parent 427de7c0cb
commit 872e5c1818
3 changed files with 50 additions and 6 deletions
+3 -3
View File
@@ -101,16 +101,16 @@
<div class="pagination">
@if (Model.CurrentPage > 1)
{
<a class="page-btn" href="/blog?page=@(Model.CurrentPage - 1)@(!string.IsNullOrEmpty(Model.ActiveCat) ? "&category=" + Model.ActiveCat : "")"></a>
<a class="page-btn" href="/blog?pg=@(Model.CurrentPage - 1)@(!string.IsNullOrEmpty(Model.ActiveCat) ? "&category=" + Model.ActiveCat : "")"></a>
}
@for (int p = 1; p <= Model.TotalPages; p++)
{
<a class="page-btn @(p == Model.CurrentPage ? "active" : "")"
href="/blog?page=@p@(!string.IsNullOrEmpty(Model.ActiveCat) ? "&category=" + Model.ActiveCat : "")">@p</a>
href="/blog?pg=@p@(!string.IsNullOrEmpty(Model.ActiveCat) ? "&category=" + Model.ActiveCat : "")">@p</a>
}
@if (Model.CurrentPage < Model.TotalPages)
{
<a class="page-btn" href="/blog?page=@(Model.CurrentPage + 1)@(!string.IsNullOrEmpty(Model.ActiveCat) ? "&category=" + Model.ActiveCat : "")"></a>
<a class="page-btn" href="/blog?pg=@(Model.CurrentPage + 1)@(!string.IsNullOrEmpty(Model.ActiveCat) ? "&category=" + Model.ActiveCat : "")"></a>
}
</div>
}
+4 -2
View File
@@ -20,9 +20,11 @@ public class BlogIndexModel : PageModel
public int TotalPosts { get; private set; } = 0;
public string? ActiveCat { get; private set; }
public async Task<IActionResult> OnGetAsync(int page = 1, string? category = null)
// NOTE: the query param is "pg", not "page" — "page" is a reserved route token in
// Razor Pages and never binds here, which silently pins every request to page 1.
public async Task<IActionResult> OnGetAsync([FromQuery(Name = "pg")] int pg = 1, string? category = null)
{
CurrentPage = page < 1 ? 1 : page;
CurrentPage = pg < 1 ? 1 : pg;
ActiveCat = category;
var q = _db.BlogPosts.Include(p => p.Category).Where(p => p.IsPublished);