Pagination - Web Matrix / Razor

I used Mike Brind's guide to set up pagination that works. I also used bootstrap to create more convenient page navigation at the bottom of my page. Could you tell me what I need to do to make the NEXT and PREV buttons work? I imagine that it is something like I + 1 and i-1, but I have not figured it out yet. here is my code:

EDITED CODE:

//Paging var pageSize = 6; var totalPages = 0; var count = 0; var page = UrlData[0].IsInt() ? UrlData[0].AsInt() : 1; var offset = (page -1) * pageSize; var db = Database.Open("StayInFlorida"); var sql = "Select Count(*) From PropertyInfo "; count = (int)db.QueryValue(sql); totalPages = count/pageSize; if(count % pageSize > 0){ totalPages += 1; } sql = "SELECT PropertyName, PropertyID, ResortName, NumBedrooms, NumBathrooms, NumSleeps, BriefDescription, PrimaryImage FROM PropertyInfo "+ "Order By PropertyID OFFSET @0 ROWS FETCH NEXT @1 ROWS ONLY;"; var result = db.Query(sql, offset, pageSize); <!--Pagination Start--> <div class="pagination pagination-centered"> <ul> @{ if(page > 1){ <li><a href="/portfolio1/@(page-1)">Prev</a></li> } for (var i = 1; i < totalPages + 1; i++){ <li><a href="/portfolio1/@i">@i</a></li> } if(page > 1){ <li><a href="/portfolio1/@(page + 1)">Next</a></li> } } </ul> </div> <br> <!--Pagination Finish--> 
+4
source share
1 answer

Presumably, do you want the next or previous button to appear if there is a next or previous page? If this is the case, it is assumed that you are tracking the current page number in a variable called a page, here is how you can do it:

 <!--Pagination Start--> <div class="pagination pagination-large"> <ul> @if(page > 1){ <li><a href="/portfolio1/@(page-1)">Prev</a></li> } for (var i = 1; i < totalPages + 1; i++){ <li><a href="/portfolio1/@i">@i</a></li> } if(page < totalPages){ <li><a href="/portfolio1/@(page + 1)">Next</a></li> } </ul> </div> <br> <!--Pagination Finish--> 
+3
source

All Articles