I am using the following code to display properties of content of a certain Doc Type within the site. i am able to display the url and Name ok, but get error when attempting to display the 'image' property of the Doc type with @Umbraco.Media(item.image).Url.
Error rendering images
Dear Umbraco Team
I am using the following code to display properties of content of a certain Doc Type within the site. i am able to display the url and Name ok, but get error when attempting to display the 'image' property of the Doc type with @Umbraco.Media(item.image).Url.
@foreach(var item in Model.Content.AncestorOrSelf(1).Descendants().Where(x => x.DocumentTypeAlias == "DocType")) { <a href="@item.Url">@item.Name><img src="@Umbraco.Media(item.Image).Url"></a> }
Any ideas/guidance good people of Our Umbraco ?
Thanks Dibs
Hi Dibs,
What kind of error do you get? Given your example,
itemshould be of the typeIPublishedContent. The interface does not specify animageproperty.If you have added an
imageproperty to your document type, you should be able to get the value like:Also notice that the property alias is case sensitive - meaning
imageis not the same asImage.Hope this helps ;)
Thanks Anders
that gave me a starter for ten, i used the following :
Thanks Dibs
As .TypedMedia(int id) Given a node ID , returns a IPublishedContent Media entity
you can simply use mediaItem.Url to fetch the content of "UmbracoFile" this being a reserved core property.
see https://our.umbraco.org/documentation/Reference/Querying/UmbracoHelper/ the Working with Media section.
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.