Richard1996
Richard1996

Reputation: 105

Umbraco - reference a published image

I'm trying to ref a published image in Umbraco but 'MediaById' seems to be incorrect, what is the correct way to reference this?

<img src="@Model.MediaById("focusImage") alt="@Model.GetPropertyValue("focusAltText")/>

Upvotes: 0

Views: 96

Answers (1)

wingyip
wingyip

Reputation: 3536

Try

@{
   var mediaId = Model.GetPropertyValue<int>("focusImage");
   var media = Umbraco.TypedMedia(mediaId);
}

<img src="@media.Url" alt="@Model.GetPropertyValue("focusAltText")/>

Upvotes: 2

Related Questions