Copied to clipboard

Flag this post as spam?

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

  • Proxicode 127 posts 323 karma points
    Apr 21, 2017 @ 21:07

    Umbraco 7.6 and Media

    Hey everyone!

    I am working with 7.6 and made a pretty basic Archetype called "Partners" which looks like this...

    enter image description here

    So a partner is just a name, a logo, and a link. partnerName is a simple text string, partnerLogo is a MediaPicker (with multi items and folder select disabled), and partnerLink is from another of Kevin's awesome projects-- UrlPicker.

    My trouble is in getting the image from the media picker while looping through the Archetype. My code is below.

    <section class="partners_in">
            @foreach (var partner in Model.Content.GetPropertyValue<ArchetypeModel>("partners"))
                    @if (partner.HasValue("partnerLink"))
                        var widgetLink = partner.GetValue<UrlPicker>("partnerLink");
                        var linkTarget = widgetLink.Meta.NewWindow ? "_blank" : null;
                        var linkUrl = widgetLink.Url;
                        if (widgetLink.Type == UrlPicker.UrlPickerTypes.Url)
                            if (!string.IsNullOrEmpty(linkUrl) && !(linkUrl.StartsWith("http://") && !(linkUrl.StartsWith("https://"))))
                                linkUrl = "http://" + linkUrl;
                        <a href="@linkUrl" target="@linkTarget" class="link">
                                <img src="@Umbraco.Media(partner.GetValue("partnerLogo")).Url" alt="img" />

    This does run, but it just outputs

    <img src(unknown) alt="img">

    When I pull this out and run it on it's own line


    It returns


    So I'm not sure if this has anything to do with Archetype or if this is just a change in how Media should be returned in 7.6. I've always had success using @Umbraco.Media(string or int) but it seems that no Media method is expecting a Udi. I've read the little bit of info that I can find but I'm not having much luck. Thanks for any pointers on this.



  • Dennis Adolfi 1082 posts 6448 karma points MVP 6x c-trib
    Apr 21, 2017 @ 21:18
    Dennis Adolfi

    Hi Proxicode.

    Yes, this is an issue with 7.6 but it is soon solved. Read the comments in this thread:

    Have a great weekend!

  • Dave Woestenborghs 3504 posts 12134 karma points MVP 9x admin c-trib
    Apr 22, 2017 @ 07:40
    Dave Woestenborghs

    Hi Proxicode,

    This is because in v7.6 links to items from pickers(media, content, multinode,...) are not stored as integer id's anymore, but in the new UDI format.

    See this topic which had the same issue for the related links datatype :

    Luckily the core value convertors package got integrated in the core in v7.6.

    Now you can do this in your code :


    This will return a IPublished content item representing the selected media item.


  • Proxicode 127 posts 323 karma points
    Apr 22, 2017 @ 15:54

    Ah thanks a lot Dave! This got me going.

    Seems worth mentioning that this this doesn't work...

         <img src="@partner.GetValue<IPublishedContent>("partnerLogo").Url" alt="img" />

    no errors, builds fine, but nothing displays.

    This however DOES work!

            var imageUrl = partner.GetValue<IPublishedContent>("partnerLogo").Url;
         <img src="@imageUrl" alt="img" />

    Thanks again for taking the time to help me out. Have a good one!


  • Paul Wright (suedeapple) 277 posts 704 karma points
    Apr 28, 2017 @ 12:22
    Paul Wright (suedeapple)

    Untested but this might work:

    <img src="@(partner.GetValue<IPublishedContent>("partnerLogo").Url)" alt="img" />
  • Proxicode 127 posts 323 karma points
    Apr 29, 2017 @ 16:52

    Hey Paul - Nice - yeah your solution does work as well!

    One of those crazy syntax things that I'm sure has a meaning that I don't understand as to why this doesn't work

    <img src="@partner.GetValue<IPublishedContent>("partnerLogo").Url" alt="img" />

    but this does

    <img src="@(partner.GetValue<IPublishedContent>("partnerLogo").Url)" alt="img" />

    Thanks for chiming in on this :-)


  • Tiago 12 posts 94 karma points
    Nov 07, 2017 @ 15:01

    I know this an extremely late reply, but I came across this thread, and your reply, and thought Id answer your question.

    The reason that doesn't work is because without the parenthesis the razor parser will interpret the '<...>' as an html element which means you will be trying to access the getPropertyValue method as a property of the product object and not as a method.

Please Sign in or register to post replies

Write your reply to: