Copied to clipboard

Flag this post as spam?

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


  • pubudu 30 posts 133 karma points
    Jul 23, 2019 @ 11:44
    pubudu
    0

    I tried to get the page background image using media picker. I use the below code. but it does not work. Is there any other code to it? enter image description here

    style="background: url(@Umbraco.AssignedContentItem.GetProperty("backImage"))
    
  • David Challener 80 posts 444 karma points c-trib
    Jul 24, 2019 @ 09:06
    David Challener
    100

    Hi,

    Does your code for retrieving "backImage" return anything? I can't quite tell from the image whether you're in a partial or in a template with the model where this image is located.

    Once you've got the field, depending on your version of Umbraco and whether Property Value Converters are enabled you may need to convert the Media id to a media object and then get it's URL.

    @{
    
    var backgroundUrl = String.Empty;    
    var backgroundImage = Umbraco.TypedMedia(Model.Content.GetPropertyValue<int>("backImage"));
    if (backgroundImage != null)
    {
         backgroundUrl = backgroundImage.Url;
    }
    
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft