I'm using Umbraco 7.6.1 and I'm trying to get the url for a media image using the code below in razor.
@{
var bannerMediaItem = Umbraco.TypedMedia(Model.Content.Image);
var bannerUrl = bannerMediaItem.Url;
}
But bannerMediaItem is always null even though I know it exists. If I do this..
@Model.Content.Image
It returns the id of the image e.g. 1086
In Umbraco v7.6 and above, there is now a new thing called UDI. Find out more about UDI here. https://our.umbraco.org/documentation/reference/querying/Udi
So instead of your media item having a numeric id, by default it will have an id like this: umb://media/39d3ac707d634953ab52642d5037855c
Here is how you get the media url when the id is one of the new type:
string imageUrl = Model.Content.GetPropertyValue<IPublishedContent>("headerImage").Url;