Skip to content

Commit 2e70022

Browse files
committed
Corrected Pagination
1 parent 850a1df commit 2e70022

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

LinkDotNet.Blog.Web/Pages/Index.razor

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@
1919
<ShortBlogPost BlogPost="_currentPage[i]" UseAlternativeStyle="@(i % 2 != 0)"></ShortBlogPost>
2020
}
2121
</div>
22-
<BlogPostNavigation CurrentPage="@_currentPage" OnPageChanged="GetPage"></BlogPostNavigation>
22+
<BlogPostNavigation CurrentPage="@_currentPage" OnPageChanged="@GetPage"></BlogPostNavigation>
2323
</section>
2424
@code {
2525
IPagedList<BlogPost> _currentPage = new PagedList<BlogPost>(Array.Empty<BlogPost>(), 1, 1);
2626

2727
protected override async Task OnInitializedAsync()
2828
{
29-
_currentPage = await _repository.GetAllAsync(p => p.IsPublished, b => b.UpdatedDate, pageSize: 1);
29+
_currentPage = await _repository.GetAllAsync(p => p.IsPublished, b => b.UpdatedDate, pageSize: 3);
3030
}
3131

3232
private string GetAbsolutePreviewImageUrl()
@@ -48,7 +48,7 @@
4848

4949
private async Task GetPage(int newPage)
5050
{
51-
_currentPage = await _repository.GetAllAsync(p => p.IsPublished, b => b.UpdatedDate, pageSize: 1, page:
51+
_currentPage = await _repository.GetAllAsync(p => p.IsPublished, b => b.UpdatedDate, pageSize: 3, page:
5252
newPage);
5353
}
5454
}

LinkDotNet.Blog.Web/Shared/BlogPostNavigation.razor

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,11 @@
33
<nav aria-label="Page navigation example">
44
<ul class="pagination justify-content-center">
55
<li class="page-item @(!CurrentPage.IsFirstPage ? string.Empty : "disabled")">
6-
<a class="page-link" href="#" tabindex="-1">Previous</a>
6+
<a class="page-link" href="#" tabindex="-1" @onclick="PreviousPage">Previous</a>
77
</li>
8-
<li class="page-item"><a class="page-link @(!CurrentPage.IsFirstPage ? string.Empty : "disabled")"
9-
href="#"
10-
@onclick="PreviousPage">(@CurrentPage.PageNumber - 1)</a></li>
11-
<li class="page-item">
12-
<a class="page-link @(!CurrentPage.IsLastPage ? string.Empty : "disabled")"
13-
@onclick="NextPage">
8+
<li class="page-item @(!CurrentPage.IsLastPage ? string.Empty : "disabled")">
9+
<a class="page-link"
10+
@onclick="NextPage"
1411
href="#">Next</a>
1512
</li>
1613
</ul>
@@ -30,11 +27,11 @@
3027

3128
private async Task PreviousPage()
3229
{
33-
await PageHasChanged(CurrentPage.PageCount - 1);
30+
await PageHasChanged(CurrentPage.PageNumber - 1);
3431
}
3532

3633
private async Task NextPage()
3734
{
38-
await PageHasChanged(CurrentPage.PageCount + 1);
35+
await PageHasChanged(CurrentPage.PageNumber + 1);
3936
}
4037
}

0 commit comments

Comments
 (0)