Copied to clipboard

Flag this post as spam?

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


  • Peter van Geffen 54 posts 290 karma points
    Nov 07, 2019 @ 10:13
    Peter van Geffen
    0

    Get an image (random) from a media folder

    Hi,

    What i wanted to achieve is to get a single image in a random order from a media folder (by id)

    This worked for in V7 (looking at previous projects), but now in V8 i'm stuck.

    @{
        var galleryAlbum = Umbraco.Media(1210);
        foreach(var image in galleryAlbum.Children.RandomOrder().Take(1)){
            <div class="parallax-window" data-parallax="scroll" data-image-src="@Url.GetCropUrl(image, "Hero")"></div>
        }
    }
    

    Could someone help me out?

  • Alex Skrypnyk 6163 posts 24143 karma points MVP 8x admin c-trib
    Nov 07, 2019 @ 13:54
    Alex Skrypnyk
    100

    Hi Peter

    What about this approach:

    var galleryAlbum = Umbraco.Media(1210);
    var theList = galleryAlbum.Children.ToList();
    var randomImage = theList.ElementAt(new Random(DateTime.Now.Millisecond).Next(theList.Count()));
    
  • Peter van Geffen 54 posts 290 karma points
    Nov 08, 2019 @ 09:55
    Peter van Geffen
    0

    Thank you very much! Exactly what i wanted .

Please Sign in or register to post replies

Write your reply to:

Draft