Copied to clipboard

Flag this post as spam?

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


  • bh 63 posts 296 karma points
    5 days ago
    bh
    0

    I'm doing this...

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
        Layout = "Page.cshtml";
    
        var img = Umbraco.Media(Model.Content.GetPropertyValue("homeHeroImage")).UmbracoFile;
    }
        <img src="@img" />
    

    @img is null for some reason. When I check homeHeroImage it's returning the correct media item id. What am I missing?

  • Alex Skrypnyk 3895 posts 13826 karma points mvp
    5 days ago
    Alex Skrypnyk
    100

    Hi Bh

    Use this code:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
        Layout = "Page.cshtml";
    
        var img = Umbraco.TypedMedia(Model.Content.GetPropertyValue<int>("homeHeroImage")).Url;
    }
    <img src="@img" />
    
  • bh 63 posts 296 karma points
    5 days ago
    bh
    1

    Ha. I just found this documentation. But, you beat me to it. Thanks as always Alex!

    https://our.umbraco.org/documentation/getting-started/Backoffice/Property-Editors/Built-in-Property-Editors/Media-Picker

  • Jeavon Leopold 2928 posts 12596 karma points admin mvp c-trib
    5 days ago
    Jeavon Leopold
    0

    Assuming homeHeroImage is a media picker you should use:

    var img = Model.Content.GetPropertyValue<IPublishedContent>("homeHeroImage").Url;
    
Please Sign in or register to post replies

Write your reply to:

Draft