Copied to clipboard

Flag this post as spam?

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


  • Joel Hansen 38 posts 96 karma points
    May 31, 2015 @ 01:15
    Joel Hansen
    0

    Missing SortOrder on Media Items - It always returns 0 (Umbraco 7)

    Please bear with me if this has already been answered elsewhere. I have seen some other folks posting similar problems, but still no solution.

    I'm iterating over a number of media items, and I want to sort them but it seems not to work whatever I do.

     

    Here is an example, which doesn't sort the items:

    var contacts = Umbraco.TypedMedia(1234).Descendants("Contact").OrderBy("SortOrder").ToList();

     

    The SortOrder properties of all the items are all 0 (zero), like if I do this:

    @contacts.Last().SortOrder

     

    Sorting on this very same data actually works with XSLT. I can also see the SortOrder values in the Umbraco sorting UI.

    I hope someone can point me in the right direction here.

    Thanks!

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    May 31, 2015 @ 11:27
    Dennis Aaen
    0

    Hi Joel,

    From your code I can see that you are using strongly typed Razor. What if you are doing something like this, would it then work.

    Try change

    var contacts = Umbraco.TypedMedia(1234).Descendants("Contact").OrderBy("SortOrder").ToList();
    

    To

    var contacts = Umbraco.TypedMedia(1234).Descendants("Contact").OrderBy(x => x.SortOrder).ToList();
    

    Hope this helps,

    /Dennis

  • Joel Hansen 38 posts 96 karma points
    May 31, 2015 @ 14:41
    Joel Hansen
    0

    Hi Dennis

    Thanks for your reply.

    Actually I wrote it just like you suggested in the first place, and then tried the strongly typed afterwards.

    None of it works, I just tried it again now to make sure.

    Any other good ideas? :)

    / Joel

Please Sign in or register to post replies

Write your reply to:

Draft