Copied to clipboard

Flag this post as spam?

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


  • bh 444 posts 1544 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 6150 posts 24110 karma points MVP 8x 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 444 posts 1544 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 3074 posts 13632 karma points MVP 11x 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;
    
Please Sign in or register to post replies

Write your reply to:

Draft