Display Image from Media Library in Umbraco 7

后端 未结 8 2039
野性不改
野性不改 2021-02-04 00:22

This should be something embarrassingly simple, but I can\'t get it to work: I\'d simply like to display an image that was uploaded to the Umbraco Media Library (Umbraco 7.1.1)

相关标签:
8条回答
  • 2021-02-04 01:12

    This worked for me, from the Umbraco 6 Media docs, here

    var bannerImage = Umbraco.TypedMedia(Model.Content.GetPropertyValue("plainImage"));
    
    <div class="my-banner-wrapper" style="background-image: url(@bannerImage.GetPropertyValue("umbracoFile"));">
        <!-- some irrelevant content -->
    </div>
    
    0 讨论(0)
  • 2021-02-04 01:13

    I found this way easy and clean:

    @if (CurrentPage.Image != null && !(CurrentPage.Image is Umbraco.Core.Dynamics.DynamicNull))
    {
        var m = Umbraco.Media(CurrentPage.Image);
    
        <img src="@m.Url" alt="@m.UrlName" />
    }
    

    I hope that it helps somebody else

    0 讨论(0)
提交回复
热议问题