Copied to clipboard

Flag this post as spam?

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


  • Inmedia 124 posts 176 karma points
    Apr 29, 2012 @ 18:02
    Inmedia
    0

    OrderBy descending or ascending - How to?

    I have  a Razor script that creates a list of subpages and list them by a set number of items and orders them.

    But I need to reverse the OrderBy function, so that the most recent nodes get listed first.

    My razor file looks like this:

     

    @inherits umbraco.MacroEngines.DynamicNodeContext

    @{ var numberOfItems = 2; }
    <ul>
        @foreach (var item in @Model.Children.Where("Visible").Take(numberOfItems).OrderBy("UpdateDate")) {
            
            <li>
              <a href="@item.Url">@item.Name</a>
            </li>
        }
    </ul>

     

    I am pretty sure its a fairly simple thing to achieve, but im new to Razor :) Can anyone tell me how to do this?


  • Owen 123 posts 246 karma points
    Apr 29, 2012 @ 19:13
    Owen
    0

    here is a simple come from the other post:

    var events =newDynamicNode(1109).GetChildrenAsList.Items.OrderByDescending((dynamic dn)=> dn.dateTime);
  • Inmedia 124 posts 176 karma points
    Apr 29, 2012 @ 22:47
    Inmedia
    0

    That doesn't seem to work at all... Just gives an error.

Please Sign in or register to post replies

Write your reply to:

Draft