I have been searching for one simple thing and that is showing an image in my razorview.
For some reason Umbraco.Media doesn't exist, can somebody help?
I'm running Umbraco 7.5.6
The Umbraco.Media(int) is a UmbracoHelper and in order for you to be able to use it using the "Umbraco" prefix your view needs to inherit either UmbracoTemplatePage or UmbracoViewPage. See example:
@inherits Umbraco.Web.Mvc.UmbracoTemplatePage<IPublishedContent>
@{
Layout = null;
var mediaId = 1107;
var mediaItem = Umbraco.Media(mediaId);
}
<img src="@mediaItem.Url"/>
Now, if you dont want you view to inherit from UmbracoTemplatePage or UmbracoViewPage that's fine, but then you need to create you own instance of the UmbracoHelper and use it instead of the "Umbraco" prefix. See example:
@{
Layout = null;
var umbracoHelper = new UmbracoHelper(UmbracoContext.Current);
var mediaId = 1107;
var mediaItem = umbracoHelper.Media(mediaId);
}
<img src="@mediaItem.Url"/>
Show umbraco image
I have been searching for one simple thing and that is showing an image in my razorview. For some reason Umbraco.Media doesn't exist, can somebody help? I'm running Umbraco 7.5.6
Can somebody explain what the best way is to get the url of an image by a nodeid?
Hi Bunnynut.
The Umbraco.Media(int) is a UmbracoHelper and in order for you to be able to use it using the "Umbraco" prefix your view needs to inherit either UmbracoTemplatePage or UmbracoViewPage. See example:
Now, if you dont want you view to inherit from UmbracoTemplatePage or UmbracoViewPage that's fine, but then you need to create you own instance of the UmbracoHelper and use it instead of the "Umbraco" prefix. See example:
Good luck!!
Hi Dennis,
Thanks a lot that really helped me!
Awesome!! Glad I could help!
Have a great day!
is working on a reply...