0
votes

I've been trying to utilise Umbraco 8 in a new project. (I've got C# experience but never used Umbraco before)

I've added templates and set it up to accept data, however I've set up a "Home" DocType and added an Image Selector. After setting and publishing the data, I'm now trying to update the template to display the Image, and keep running into errors, I've tried:

var backgroundImageId = Model.Value("backgroundImage");
var backgroundImage = Umbraco.Media(backgroundImageId);
@Model.Value("backgroundImage").Url

And a bunch of others which haven't panned out. I just can't seem to get it to work.

Any suggestions appreciated.

2

2 Answers

4
votes
var backgroundImage = Model.Value<IPublishedContent>("backgroundImage").Url;

Fouund the solution to this, converting the type to published content seems to do the trick.

0
votes

There are several ways you can get this.

IPublishedContent contentbackgroundImage = umbracoHelper.TypedContent(backgroundImageId);

var backgroundImage = contentbackgroundImage?.GetPropertyValue<IPublishedContent>("backgroundImage");

you can do like this way on the razor pages

@{
    var backgroundImage = Model.GetValue<IPublishedContent>("backgroundImage")
}

from this you can access properies like url, name ,alies ect.