Copied to clipboard

Flag this post as spam?

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


  • JamesW 18 posts 128 karma points
    Jun 15, 2017 @ 10:13
    JamesW
    0

    Get Url of media picker item of parent.

    Hi

    I'm trying to display the Url of media that is selected from the media picker in the parent of the current page, but it is always blank.

    This returns the correct Id of the media item:

    var mainImage = Model.Content.Parent.GetPropertyValue("mainImage");
    

    But when I try and get the Url it's doesn't return anything:

    var imageUrl = @Umbraco.Media(mainImage).Url;
    

    Thanks for any help.

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jun 16, 2017 @ 08:01
    Jeavon Leopold
    0

    Hi James,

    If you are using Umbraco v7.6 then you should be able to do this:

    var mainImageUrl = Model.Content.Parent.GetPropertyValue<IPublishedContent>("mainImage").Url;
    

    If you are on a version before v7.6 then it should be like this:

    var mainImage = Model.Content.Parent.GetPropertyValue<int>("mainImage");
    var imageUrl = Umbraco.TypedMedia(mainImage).Url;
    

    Jeavon

Please Sign in or register to post replies

Write your reply to:

Draft