Razor and media question, how do I display an image that has been uploaded in the Media section?
I searched around and found absolutely nothing like what I was expecting, some XSLT stuff that's not for me and some other code that made no sense as it was out of context.Here's what I have:A jpg uploaded into Media sectionA document type with a media picker property called mylogo.The corresponding razor template that I want to use this jpg in.I came up with this:@using umbraco.cms.businesslogic.media...<img src="@(new Media(int.Parse(Umbraco.Field("mylogo").ToString())).GetImageUrl())" />Is there any better / easier way of displaying an image, this seems such a basic thing to want to do?Cheers.
I looked, couldn't find anything in DAMP that I could follow or how I could use it in my template, I don't really need an image gallery, just one image URL from the Media.
Sure, new Media(int.Parse(Umbraco.Field("mylogo").ToString())).GetImageUrl() that I have will work, I'm just looking for a shortcut way of doing this.
Razor and media question, how do I display an image that has been uploaded in the Media section?
I searched around and found absolutely nothing like what I was expecting, some XSLT stuff that's not for me and some other code that made no sense as it was out of context.Here's what I have:A jpg uploaded into Media sectionA document type with a media picker property called mylogo.The corresponding razor template that I want to use this jpg in.I came up with this:@using umbraco.cms.businesslogic.media...<img src="@(new Media(int.Parse(Umbraco.Field("mylogo").ToString())).GetImageUrl())" />Is there any better / easier way of displaying an image, this seems such a basic thing to want to do?Cheers.
You could try the DAMP Gallery. It's an image gallery and the complete source is available so you can see exactly how it works.
Jeroen
Sorry about the formatting there, tried to correct it, failed.
Thanks for the replies so far.
@Morten:
My page @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
So it doesn't look like I have access to the Model in that way, do I need to do something different?
@Jeroen: I'll take a look at the code, cheers.
I looked, couldn't find anything in DAMP that I could follow or how I could use it in my template, I don't really need an image gallery, just one image URL from the Media.
Sure, new Media(int.Parse(Umbraco.Field("mylogo").ToString())).GetImageUrl() that I have will work, I'm just looking for a shortcut way of doing this.
Don't use "new Media()". It's really slow to use. Use TypedMedia or Media in the UmbracoHelper: http://our.umbraco.org/documentation/Reference/Mvc/views
Example:
More info here: http://umbraco.com/follow-us/blog-archive/2012/10/30/getting-started-with-mvc-in-umbraco-410.aspx
Jeroen
Thanks for the heads-up, I then found this:
http://our.umbraco.org/documentation/Using-Umbraco/Backoffice-Overview/Property-Editors/Built-in-Property-Editors/Media-Picker
Which also shows a use of Umbraco.Media for the dynamic equivalent.
I might have to write my own helper to shortcut this.
Thanks for your time.
Tim
is working on a reply...