Skip to content

Commit

Permalink
Fix pagination (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
KevBat authored Mar 22, 2021
1 parent cb517ac commit 4093676
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/Views/Blog/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
@{
int currentPage = int.Parse(ViewContext.RouteData.Values[Constants.page] as string ?? "0");

int pageCount;
pageCount = int.TryParse(ViewData[Constants.TotalPostCount].ToString(), out pageCount) ? 0 : pageCount / 2;
int totalPosts;
totalPosts = int.TryParse(ViewData[Constants.TotalPostCount].ToString(), out totalPosts) ? totalPosts : 0;

int totalPages = (totalPosts / this.settings.Value.PostsPerPage) - (totalPosts % this.settings.Value.PostsPerPage == 0 ? 1 : 0);
}

@await foreach (var post in Model)
Expand All @@ -13,7 +15,7 @@
}

<nav class="pagination container" aria-label="Pagination">
@if ((await Model.AnyAsync()) && currentPage < pageCount)
@if ((await Model.AnyAsync()) && currentPage < totalPages)
{
<a rel="prev" href="@ViewData[Constants.prev]" title="Older posts">&laquo; Older</a>
}
Expand All @@ -24,7 +26,7 @@
<br /><br />

@section Head {
@if ((await Model.AnyAsync()) && currentPage < pageCount)
@if ((await Model.AnyAsync()) && currentPage < totalPages)
{
<link rel="prev" href="@ViewData[Constants.prev]" />
}
Expand Down

0 comments on commit 4093676

Please # to comment.