Copied to clipboard

Flag this post as spam?

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


  • Leon 101 posts 489 karma points
    Feb 04, 2015 @ 12:38
    Leon
    0

    Getting Img Url from media picker in foreach item in selection

    How do I get the actual image url of a media picker image property in a foreach?

    @foreach(var item in selection){
        <li>
            <a href="@item.Url">
                <img src="@item.tileImage.???" />
            </a>
    
        </li>
    }
    

    Hope you can help.

    Leon

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Feb 04, 2015 @ 12:44
    Dennis Aaen
    100

    Hi Leon,

    What if you do something like this:

    @foreach(var item in selection){
        <li>
            <a href="@item.Url">
               @if (item.HasValue("mediaPickerAlias")){                                        
                    var dynamicMediaItem = Umbraco.Media(item.mediaPickerAlias);
                    <img src="@dynamicMediaItem.umbracoFile" alt="@dynamicMediaItem.Name"/>
                }     
            </a>

        </li>
    }

    And remember to chage this mediaPickerAlias so it match the alias of the media picker on the document type. Try also to see the documentation for the media picker here. http://our.umbraco.org/documentation/Using-Umbraco/Backoffice-Overview/Property-Editors/Built-in-Property-Editors/Media-Picker

    Hope this helps,

    /Dennis

  • Leon 101 posts 489 karma points
    Feb 04, 2015 @ 13:01
    Leon
    0

    YAY!!!

    Thank you very much. It worked first time. You're the best!!

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Feb 04, 2015 @ 13:11
    Dennis Aaen
    0

    Hi Leon,

    You are welcome, happy to help. - Could you please mark the issue as solved so others can go straight to the solution if they should come across the same issue. You do this by click the green tick with my gravatar picture in the left corner. It´s only possible to mark your answer as the solution. So click on the post with the solution. :-)

    /Dennis

Please Sign in or register to post replies

Write your reply to:

Draft