Copied to clipboard

Flag this post as spam?

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


  • Pete 213 posts 285 karma points
    Apr 16, 2013 @ 16:36
    Pete
    1

    Order by first letter?

    I'm trying to get some nodes by their first letter, and use the razor paging, briefly using this:

    List<DynamicNode> nl = @homeNode.Children.Items;
    pagesToList = nl.Where(x => x.Name.StartsWith(currentLetter));

    Then for the paging:

    @foreach(dynamic item in pagesToList.Skip(currentPage*itemsPerPage).Take(itemsPerPage))
    {
    .....
    }


    But I get a 'object' does not contain a definition for 'Skip' error.

  • Fuji Kusaka 2203 posts 4220 karma points
    Apr 16, 2013 @ 17:18
    Fuji Kusaka
    0

    Hi Pete,

    For your paging to work you need to define number of page for the skip.

     

    int itemsPerPage= 10; // no of  pages per page
    int page = 1; //  viewing page

    And make use of some QueryString for the paging 

     

    if (!int.TryParse(Request.QueryString["page"], out page)){
    page = 1;
    }

     

    @foreach(dynamic item in pagesToList.Skip((page-1)*itemsPerPage).Take(itemsPerPage)){

    }
       @for(int p =1; p < totalPages + 1; p++){
            string select = (p == page)? "selected": "";
            <li ><a href="?page=@p" title="Go to page @p of results">@p</a></li>
        }

     

  • Pete 213 posts 285 karma points
    Apr 17, 2013 @ 11:12
    Pete
    0

    Thanks fuji, I've already got the code you mention in there - I just didn't put it in my post above, I was just highlighting that:

    pagesToList = nl.Where(x => x.Name.StartsWith(currentLetter));

    creates the object' does not contain a definition for 'Skip' error. on the:

    @foreach(dynamic item in pagesToList.Skip(currentPage*itemsPerPage).Take(itemsPerPage))

     

     

Please Sign in or register to post replies

Write your reply to:

Draft