Copied to clipboard

Flag this post as spam?

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


  • Guy Pucill 23 posts 73 karma points
    Feb 22, 2015 @ 20:25
    Guy Pucill
    0

    .OrderByDescending("Id")

    I am having trouble using .OrderByDescending("Id") in sorting items before running throug items to render html. My code works without .OrderByDescending("Id") but adding does not throw error but only shows blank rendering in browser:

    @inherits umbraco.MacroEngines.DynamicNodeContext
    @{ 
    var  folderId = Model.GetPropertyValue("mediaFolder");
    
        var  chosenMedia  =  Model.MediaById(@folderId).OrderByDescending("Id");
    
        if  (chosenMedia.NodeTypeAlias  ==  "Folder")
     {
         foreach  (var  img  in  chosenMedia.Children)
         {
             if  (img.NodeTypeAlias  ==  "Image")
             {                   
                 <div>
                     Navn: @img.name
                 <img  src="@img.umbracoFile" width="700px" />
                         </div>
             }
         }
     } 
    

    }

  • Guy Pucill 23 posts 73 karma points
    Feb 22, 2015 @ 20:47
    Guy Pucill
    0

    .Children.OrderBy("Name") works fine. .Children.OrderByDescending("Name") does not.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Feb 22, 2015 @ 20:47
    Jan Skovgaard
    1

    Hi Guy

    I think you should put the OrderByDescending on your look rather than in your chosenMedia variable so the code looks like this instead

    @inherits umbraco.MacroEngines.DynamicNodeContext
    @{ 
    var  folderId = Model.GetPropertyValue("mediaFolder");
    
        var  chosenMedia  =  Model.MediaById(@folderId);
    
        if  (chosenMedia.NodeTypeAlias  ==  "Folder")
     {
         foreach  (var  img  in  chosenMedia.Children.OrderByDescending("Id"))
         {
             if  (img.NodeTypeAlias  ==  "Image")
             {                   
                 <div>
                     Navn: @img.name
                 <img  src="@img.umbracoFile" width="700px" />
                         </div>
             }
         }
     } 
    }
    

    Does that work?

    /Jan

  • Guy Pucill 23 posts 73 karma points
    Feb 22, 2015 @ 21:08
    Guy Pucill
    100

    In Umbraco version 7.2.1 assembly: 1.0.5462.37503 use:

    .Children.OrderBy("createDate desc")
    

    This does not work.

    .Children.OrderByDescending("createDate")
    
Please Sign in or register to post replies

Write your reply to:

Draft