Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • pikej 27 posts 47 karma points
    Jul 09, 2011 @ 13:15
    pikej
    0

    razor paging 2 questions

    Hi guys,

    I am using razor paging and although it works fine because I have lots of subpages I get too many links (1,2,3,4,5 and so on).

    Is there any way to display just a few first numbers instead (like 1,2,3 ..... 78)?

    Also for this project it would be great to have second paging navigation above the one mentioned consisting of next ane previous buttons. Any ideas how to do this?

    kind reagards, 

  • Dan Diplo 1554 posts 6205 karma points MVP 6x c-trib
    Jul 11, 2011 @ 15:05
    Dan Diplo
    0

    Next and previous is pretty simple. Assuming you have a variable called currentPage that holds the current page number and another called totalPages that holds the total number of pages you just do something like this:

    @if (currentPage > 1)
    {
      <a href="?page=@(currentPage-1)" title="Go to previous page">&lt; Previous</a> 
    }

    @if (currentPage < totalPages)
    {
      <a href="?page=@(currentPage+1)" title="Go to next page">Next &gt;</a>
    }
     
  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Jul 11, 2011 @ 15:25
    Sebastiaan Janssen
    0

    Similarly introduce a new variable that holds the currentpage number +5 pages and -5 pages and play with that to skip over paging results. For example when you are on page 50, only show page 45-49 on the left side and 51-65 on the right. When your looping through the pages. So when you're looping through your pages you need to test something like:

    if(currentPage >= minPageToTheLeft && currentPage <= maxPageToTheRight) {
      @currentPage
    }

    However, you're going to have to add some logic in case you're at page 1-5 or at page 73-78 (if 78 is your highest page).

  • pikej 27 posts 47 karma points
    Jul 26, 2011 @ 23:00
    pikej
    0

    many thanks for Dan and Sebastiaan,

    both solutions work wonders and saved me a lot of time.

    cheers!

     

Please Sign in or register to post replies

Write your reply to:

Draft