Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • TimH 5 posts 25 karma points
    Dec 20, 2012 @ 12:06
    TimH
    0

    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.

  • Morten 20 posts 61 karma points
    Dec 20, 2012 @ 12:32
    Morten
    0

     

    var media = Model.NodeById(Model.MyLogo);
    @:<img src="@media.NiceUrl" alt="" />
     // or
    @:<img src="@media.umbracoFile" alt="" />

     

  • Jeroen Breuer 4909 posts 12266 karma points MVP 5x admin c-trib
    Dec 20, 2012 @ 12:41
    Jeroen Breuer
    0

    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

  • TimH 5 posts 25 karma points
    Dec 20, 2012 @ 12:52
    TimH
    0

    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.

  • TimH 5 posts 25 karma points
    Dec 20, 2012 @ 13:58
    TimH
    0

    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.

  • Jeroen Breuer 4909 posts 12266 karma points MVP 5x admin c-trib
    Dec 20, 2012 @ 14:03
    Jeroen Breuer
    0

    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:

    var media = @Umbraco.TypedMedia(id); 

    More info here: http://umbraco.com/follow-us/blog-archive/2012/10/30/getting-started-with-mvc-in-umbraco-410.aspx

    Jeroen

  • TimH 5 posts 25 karma points
    Dec 20, 2012 @ 16:01
    TimH
    0

    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

  • 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.

Please Sign in or register to post replies