Copied to clipboard

Flag this post as spam?

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


  • Mike 10 posts 30 karma points
    Feb 26, 2013 @ 13:08
    Mike
    0

    Saving media off to List loses properties and OrderBy continually throws errors

    Hi, I'm using 4.7 and I'm having some trouble with looping over a set of nested Media items that I need to sort alphabetically.

    I have a set of media items that are of the same DocType that are separated by a set of folders. ie:

     

    • Folder
    • Sub-Folder
    • MediaItem1
    • MediaItem2
    • MediaItem3
    • Sub-Folder
    • MediaItem4
    • MediaItem5
    In order to get the list of all my MediaItems I have to loop over all the sub-folders and save the media items off to a list like - 
    var sortList new List<DynamicMedia>();
    Whilst adding them is fine and for another met criteria adds properties of each item to mark up within the opening loop. When trying to do the following after all that is done I get a whole set of errors.
    foreach(var sign in sortList.OrderBy("title"))
    {
     <div class="smallBook">
         
       <href="@Model.MediaById(@sign.videoContent).umbracoFile">            
         <header>
           <h2>@sign.title</h2>
         </header>
       </a>    
     </div>
    }
    Note - I am referencing @using umbraco.MacroEngines; But this gives me: 
    The type arguments for method 'System.Linq.Enumerable.OrderBy(System.Collections.Generic.IEnumerable, System.Func)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
    And then without the OrderBy in the same loop the items that had properties before I saved them to the list are unrecognised.
     'umbraco.MacroEngines.DynamicMedia' does not contain a definition for 'videoContent' and no extension method 'videoContent' accepting a first argument of type 'umbraco.MacroEngines.DynamicMedia' could be found (are you missing a using directive or an assembly reference?)
    I've checked in the original loop, to get them out the folders, that the properties exist on the media items. The type that is being added to the list is DynamicMedia and the type that 'sign' is in the above foreach is DynamicMedia (They're the same item) - but once it is saved off to that list it loses the properties and I cannot reference them.
    Any help here would be greatly appreciated.
    Cheers!

     

Please Sign in or register to post replies

Write your reply to:

Draft