Copied to clipboard

Flag this post as spam?

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


  • Simon Bowler 14 posts 34 karma points
    Jul 27, 2012 @ 14:55
    Simon Bowler
    0

    Reverse this list in Razor

    Hi,

    I have this list which goes through the child nodes and lists out the content, I want the order reverse though, does anyone know how to do that?

    @foreach (var page in @Model.Children) {                
    <tr>
    <td class="recordTitle">@page.recordTitle </td>
    <td class="recordHolder">@page.recordHolder</td>          
    </tr>
    }

    Thanks,

    Simon

  • Simon 4 posts 24 karma points
    Jul 27, 2012 @ 16:00
    Simon
    0
    @Model.Children.Reverse()
    @foreach(var page in@Model.Children){                
     <tr>
      <td class="recordTitle">@page.recordTitle </td>
      <td class="recordHolder">@page.recordHolder</td>          
     </tr>
    }

    Should work.

  • Simon Bowler 14 posts 34 karma points
    Jul 27, 2012 @ 16:26
    Simon Bowler
    0

    Thanks,

    That didnt work, thank you for your input though

    Simon

  • Simon Bowler 14 posts 34 karma points
    Jul 27, 2012 @ 16:27
    Simon Bowler
    0

    Thanks,

    That didnt work, thank you for your input though

    Simon

  • Simon Bowler 14 posts 34 karma points
    Jul 27, 2012 @ 16:44
    Simon Bowler
    0

    Thanks,

    That didnt work, thank you for your input though

    Simon

  • Barry Fogarty 493 posts 1129 karma points
    Jul 31, 2012 @ 11:40
    Barry Fogarty
    0

    If you just want to reverse the default order as it appears in the content tree:

    @Model.Children.OrderBy("id descending")

    Use the OrderBy() method to order your list by a specific property (internal or custom) - don't think there is a way natively to reverse the order but you could always write your own extension method if you really need this feature.

  • Mark Thomas 34 posts 127 karma points
    Jul 31, 2012 @ 11:44
    Mark Thomas
    0

    This works for me, but not for Children:

     

        <ul class="search-results">
            @foreach (var result in results.Reverse())
            {
                <li>
                    <href="@umbraco.library.NiceUrl(result.Id)">
                        @result.Fields["nodeName"]
                    </a>
                </li>
            }
        </ul>

    Mark.

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies