Copied to clipboard

Flag this post as spam?

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


  • k 256 posts 654 karma points
    Nov 05, 2018 @ 07:45
    k
    0

    Hello,

    I am having issue with media picker. it is not displaying the images. Please find code below :

    @foreach(var album in CurrentPage.Descendants("album"))
                        {
    
                            if(album.HasValue("pickAnAlbum"))
                            {
    
                            var typedMultiMediaPicker = album.Content.GetPropertyValue<IEnumerable<IPublishedContent>>("pickAnAlbum");
                            foreach (var item in typedMultiMediaPicker)
                            {
                                <img src="@item.Url" style="width:200px"/>
                            }
    }}
    

    Can someone please help with the above.

    Thanks,

    kusum

  • Nadine Fisch 159 posts 429 karma points
    Nov 05, 2018 @ 08:06
    Nadine Fisch
    0

    Which Umbraco Version are u using and what is the output of your typedMultiMediaPicker -variable? If it is a list of Ids, you must split the String and the url can be read by this

    <img src="@Umbraco.Media(id).Url">
    
  • k 256 posts 654 karma points
    Nov 05, 2018 @ 08:09
    k
    0

    I am using : 7.10.0

    The problem is that the picker itself is not working I am not able to get the id of the folder i picked.

  • Nadine Fisch 159 posts 429 karma points
    Nov 05, 2018 @ 08:25
    Nadine Fisch
    0

    I see here that you are asking for album.hasValue and album.Content.GetPropertyValue I think you should specifiy your variable in both cases. Is it album.content or just album?

    Here is a another question to this topic

    https://our.umbraco.com/forum/developers/razor/46969-Displaying-Images-from-Multiple-Media-Picker

  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Nov 05, 2018 @ 08:50
    Alex Skrypnyk
    1

    Hi K

    You use a mix of dynamically typed variables and strongly typed and it's not gonna work.

    Let's rewrite this code to strongly typed, something like that should give us at least understandable exceptions:

    @foreach (var album in Umbraco.AssignedContentItem.Descendants("album"))
    {
        if (album.HasValue("pickAnAlbum"))
        {
    
            var typedMultiMediaPicker = album.GetPropertyValue<IEnumerable<IPublishedContent>>("pickAnAlbum");
            foreach (var item in typedMultiMediaPicker)
            {
                <img src="@item.Url" style="width:200px" />
            }
        }
    }
    

    Best,

    Alex

  • k 256 posts 654 karma points
    Nov 05, 2018 @ 11:14
    k
    0

    Thanks Alex.

    I have tried the above code but still no image is displaying and there is no error.

  • Nadine Fisch 159 posts 429 karma points
    Nov 05, 2018 @ 11:52
    Nadine Fisch
    0

    what is the result of typedMultiMediaPicker and item . Is typedMultimediaPicker null?

  • k 256 posts 654 karma points
    Nov 05, 2018 @ 12:16
    k
    0
    @foreach (var album in Umbraco.AssignedContentItem.Descendants("album"))
    

    { if(album.HasValue("pickAnAlbum")) {

       var typedMultiMediaPicker = album.GetPropertyValue<IEnumerable<IPublishedContent>>("pickAnAlbum");
    
        if (typedMultiMediaPicker != null)
    {
    
         foreach (var item in typedMultiMediaPicker)
        {
       @item.Name
        }
        }
    }
    

    }

    I get nothing when I display typedMultiMediaPicker

  • Nadine Fisch 159 posts 429 karma points
    Nov 05, 2018 @ 12:24
  • k 256 posts 654 karma points
    Nov 05, 2018 @ 13:38
    k
    0

    The settings are ok.

    When I do same thing on a page like the below codes, it works. But if I loop it no more works.

    var typedMultiMediaPicker = Model.Content.GetPropertyValue<IEnumerable<IPublishedContent>>("pickAnAlbum");
            foreach (var item in typedMultiMediaPicker)
            {
                <img src="@item.Url" style="width:200px" />
            }
    
  • Alex Skrypnyk 6132 posts 23951 karma points MVP 7x admin c-trib
    Nov 05, 2018 @ 15:27
    Alex Skrypnyk
    0

    How many images did you select in Umbraco?

    Am I right that "pickAnAlbum" is a media folder? or it's a list of images?

  • k 256 posts 654 karma points
    Nov 06, 2018 @ 04:59
    k
    0

    I have picked a folder containing multiple images

Please Sign in or register to post replies

Write your reply to:

Draft