Copied to clipboard

Flag this post as spam?

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


  • Tim Gerhard 10 posts 125 karma points
    Sep 06, 2017 @ 10:59
    Tim Gerhard
    1

    Multiple Media Picker in Umbraco 7.6.6

    hello our.Umbraco Community

    I've got a problem with my Multiple Media Picker. I want to read out all my pictures in a Partial View with Razor.

      @{ var mediaIds = Model.Content.GetPropertyValue("pictures"); }
    
    
    
    @if (mediaIds != null)
    {
    
     <div class="imageSlider noBottom">
                <div class="container">
                    <div class="swiper-container">
                        <div class="swiper-wrapper">
            @foreach (var mediaId in mediaIds.ToString().Split(','))
            {
                var media = Umbraco.Media(mediaId);
    
    
    
                @* a single image *@
                if (media.DocumentTypeAlias == "Image")
                {
                    @Render(media);
                }
    
                @* a folder with images under it *@
                if (media.Children("Image").Any())
                {
                    foreach (var image in media.Children("Image"))
                    {
                        @Render(image);
                    }
                }
    
            }
                    </div>
                    </div>
                    <div class="sliderButtons">
                        <img src="img/galerie_arrow_left.svg" class="button-prev" alt="Slider left"/>
                        <img src="img/galerie_arrow_right.svg" class="button-next" alt="Slider right"/>
                    </div>
                </div>
            </div>
    
    
    }
    
    
    
    
    @helper Render(dynamic item)
    {
                <div class="swiper-slide"><img src="@item.umbracoFile alt="Slider image"/></div>
    
    }
    

    With: @{ var mediaIds = Model.Content.GetPropertyValue("pictures"); } i don't get the meidaIds of my Items, does someone know why this happens?

    Kind Regards Tim Gerhard

  • Alex Skrypnyk 6175 posts 24186 karma points MVP 8x admin c-trib
    Sep 06, 2017 @ 14:12
    Alex Skrypnyk
    0

    Hi Tim

    What version of Umbraco are you using? Did you enable property value converters?

    Thanks,

    Alex

  • Tim Gerhard 10 posts 125 karma points
    Sep 07, 2017 @ 05:57
    Tim Gerhard
    102

    Nevermind i found it out myself with the help of coworkers & Stack overflow.

    For the ones that are looking for the code i've used: (Works in Umbraco. 7.6.6)

    @{
         var typedMultiMediaPicker = Model.Content.GetPropertyValue<IEnumerable<IPublishedContent>>("pictures");
                                    foreach (var item in typedMultiMediaPicker)
                                    {
        <img src="@item.Url" alt="image" />
                                        if (item.DocumentTypeAlias == "Folder")
                                        {
                                            foreach (var image in item.Children("Image"))
                                            {
                                    <img src="@image.Url" alt="image" />
                                            }
                                        }
                                    }
                                }
    
Please Sign in or register to post replies

Write your reply to:

Draft