Copied to clipboard

Flag this post as spam?

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


  • bh 291 posts 976 karma points
    Nov 13, 2017 @ 20:29
    bh
    0

    Media Not Rendering

    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 5908 posts 22603 karma points MVP 4x admin c-trib
    Nov 13, 2017 @ 20:47
    Alex Skrypnyk
    101

    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 291 posts 976 karma points
    Nov 13, 2017 @ 20:57
    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 3008 posts 13221 karma points MVP 7x admin c-trib
    Nov 14, 2017 @ 10:26
    Jeavon Leopold
    0

    Assuming homeHeroImage is a media picker you should use:

    var img = Model.Content.GetPropertyValue<IPublishedContent>("homeHeroImage").Url;
    
  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies