Copied to clipboard

Flag this post as spam?

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


  • George 32 posts 65 karma points
    Jan 27, 2015 @ 10:05
    George
    0

    Display Media Picker Image in a Template (not XSL!)

    I have a document type with a media picker image (called projectImage). When I try to display the image in the template I simply get the ID of the image. In the template I'm using:

    @if (Model.Content.HasValue("projectImage"))
    {
      <img src="@Umbraco.Field("projectImage")" alt="project image" />
    }

    Can someone tell me how I display the image please? I've done lots of searches (most give xsl) but can't find something that works!

    Thanks in advance

    PS - I'm loving MVC with Umbraco - so very glad I don't have to use xsl ... I hope anyway :-)

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jan 27, 2015 @ 10:12
    Dennis Aaen
    0

    Hi George,

    Try to use this code.

    @if(Model.Content.HasValue("projectImage")){ 
        var mediaItem = Umbraco.TypedMedia(Model.Content.GetPropertyValue("projectImage"));
        <img src="@mediaItem.GetPropertyValue("umbracoFile")" alt="@mediaItem.GetPropertyValue("Name")"/>
    }

    You can find the documentation here and look at the typed MVC View Example http://our.umbraco.org/DOCUMENTATION/Using-Umbraco/Backoffice-Overview/Property-Editors/Built-in-Property-Editors/Media-Picker

    Hope this helps,

    /Dennis

  • George 32 posts 65 karma points
    Jan 27, 2015 @ 10:34
    George
    0

    Brilliant! Thank you Dennis!

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

    Hi George,

    You are welcome happy that I could help. Could you please mark the question as solved so other people that comes accross this post can go directly to the solution.

    You do this by click the little green tick on my first post in this thread.

    /Dennis 

Please Sign in or register to post replies

Write your reply to:

Draft