Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
The other day when I implemented paging on my project, it worked just fine - but now it looks very weird, and I can't figure out what the problem is.
This is how it looks like
And here is the code:
Layout = "Master.cshtml"; var pageSize = 3; var page = 1; int.TryParse(Request.QueryString["p"], out page); var items = Model.Content.Children().Where(x => x.IsDocumentType("BlogPost")).OrderByDescending(x => x.CreateDate); var totalPages = (int)Math.Ceiling((double)items.Count() / (double)pageSize); if (page > totalPages) { page = totalPages; } else if (page < 1) { page = 1; } @foreach (var blogPost in items.Skip((page - 1) * pageSize).Take(pageSize)) { <!--Article--> <article class="post-preview"> <a href="@blogPost.Url"> <h2 class="post-title">@blogPost.Name</h2> <h3 class="post-subtitle">@blogPost.GetPropertyValue("blogSubheader")</h3> </a> <p class="post-meta"> Posted by <a href="@blogPost.Url">@Model.Content.CreatorName</a> on @blogPost.CreateDate.ToString("MMMM d, yyyy") </p> </article> <hr /> } @if (totalPages > 1) { <ul class="pagination"> @if (page > 1) { <li><a href="?page=@(page-1)">Prev</a></li> } @for (int p = 1; p < totalPages + 1; p++) { var active = (p == page) ? "active" : string.Empty; <li class="@active"> <a href="?page=@p">1</a> </li> } @if (page < items.Count()) { <li><a href="?page=@(page+1)">Next</a></li> } </ul> }
Anyone?
Comment author was deleted
Well from what I can see you are always outputting 1 in the link
<li class="@active"> <a href="?page=@p">1</a> </li>
could you try doing this
<li class="@active"> <a href="?page=@p">@p</a> </li>
Are you talking about how every page says "1"? That's probably because you hardcoded a "1":
Thanks guys!
It worked!
Now when I click "next" it says - blog?page=2 in the URL - but it doesn't go to the next page...
Someone who can help me out with this problem?
Problem is here:
var page = 1; int.TryParse(Request.QueryString["p"], out page);
You're querying for 'p', when the parameter you set is 'page':
<li><a href="?page=@(page+1)">Next</a></li>
Update the first to change 'p' to 'page' and you should be fine.
You saved my day!
Thanks!
Thank you - this helped me out as well to quickly implement paging.
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
Paging problem!
The other day when I implemented paging on my project, it worked just fine - but now it looks very weird, and I can't figure out what the problem is.
This is how it looks like
And here is the code:
Anyone?
Comment author was deleted
Well from what I can see you are always outputting 1 in the link
could you try doing this
Are you talking about how every page says "1"? That's probably because you hardcoded a "1":
Thanks guys!
It worked!
Now when I click "next" it says - blog?page=2 in the URL - but it doesn't go to the next page...
Someone who can help me out with this problem?
Problem is here:
var page = 1; int.TryParse(Request.QueryString["p"], out page);
You're querying for 'p', when the parameter you set is 'page':
<li><a href="?page=@(page+1)">Next</a></li>
Update the first to change 'p' to 'page' and you should be fine.
You saved my day!
Thanks!
Thank you - this helped me out as well to quickly implement paging.
is working on a reply...