Copied to clipboard

Flag this post as spam?

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


  • Chris C 43 posts 184 karma points
    Apr 20, 2013 @ 08:22
    Chris C
    0

    Ordering media in razor

    Umbraco 6.  Trying to order the contents of a media folder, but the macro doesn't build. Here's the relevant code so far. 

    ...
    var folder = new umbraco.MacroEngines.DynamicMedia(mediaFolderId);

    string thumbUrl = "";

    <div class="gallery">
        <ul>

        @foreach (var mediaObject in folder.Descendants())
        {
            thumbUrl = mediaObject.Url.Replace(".jpg", "_thumb_200.jpg");
       
            <li>
                <img alt="@mediaObject.Name" src="@thumbUrl" /></li>
        }
        </ul>
           
    </div>

    When I try to put .OrderBy("whatever") after the folder.Descendants(), it says that dynamic node list doesn't contain a definition for OrderBy.  It says the same thing if I put folder.Children or any other variant.  Any solution?

  • gary 385 posts 916 karma points
    Apr 20, 2013 @ 14:10
    gary
    0

    Hi

    Maybe you need to cast the dynamic?

    @foreach (dynamic mediaObject in folder.Descendants())

    you may also need to check your @using statements, you may need to add something, sorry, do not use webforms so am no expert in that area.

    Hope it can move you a little way forward.

    Regards

    Gary

  • Chris C 43 posts 184 karma points
    Apr 21, 2013 @ 20:47
    Chris C
    0

    Cast the dynamic....  Ok, cast it to what? 

     

     

  • gary 385 posts 916 karma points
    Apr 21, 2013 @ 20:49
    gary
    0

    Hi

    on the foreach use dynamic and not var as above.

    Have had this problem in the past and it may help

    G

  • Chris C 43 posts 184 karma points
    Apr 21, 2013 @ 20:53
    Chris C
    0

    Ahhhh, it worked!  Muchas gracias. 

    EDIT:  To clarify for anyone else that might find this, I changed "var folder" to "dynamic folder" in the code above. 

  • gary 385 posts 916 karma points
    Apr 21, 2013 @ 21:01
    gary
    0

    Muito obrigado, o prazer é meu, porta-se bem.

    Sometimes 2 heads are better than one?

    G

     

  • Chris C 43 posts 184 karma points
    Apr 22, 2013 @ 02:16
    Chris C
    0

    Indeed. Also, just discovered that there is no implementation of OrderByDescending.  But folder.OrderBy("propertyName desc") seems to work. 

    Lovely place btw, the Algarve.  Traveled through Lagos, Salema and Sagres a year ago. 

     

     

  • Fuji Kusaka 2203 posts 4220 karma points
    Apr 22, 2013 @ 06:54
    Fuji Kusaka
    0

    You could also order media items by id

    .OrderBy("Id desc")
  • gary 385 posts 916 karma points
    Apr 22, 2013 @ 12:15
    gary
    0

    Hi Chrishtoph

    That is exactly where I have lived for the last 5 years, I know those towns very well.

    I am now on the other coast to the north of Sagres and it is even nicer, less people and beautiful coastline.

    What I am trying to bring to here is using technology to connect local businesses to the target markets, ie tourists with mobile devices, at times it is a big struggle, but hopefully soon the benefits will be seen and it can move forward.

    Hope to speak again soon

    Regards

    Gary

Please Sign in or register to post replies

Write your reply to:

Draft