Copied to clipboard

Flag this post as spam?

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


  • Eric Patton 21 posts 51 karma points
    Dec 20, 2012 @ 22:13
    Eric Patton
    0

    MVC Umbraco helper

    Hey everyone,

    I've recently switched to MVC for my templates, and I'm having a bit of trouble finding how to do things that I was able to do in Razor scripts inside of Web Forms. I read that the Umbraco helper is used for most things now that Library was being used for in the scripts.

    I've got it where I can grab content and get their properties, but I'm having trouble getting Media. I'm getting the node right (I believe) with this code:

    var featuredImage = Umbraco.Media(CurrentPage.FeaturedImage);

    The FeaturedImage piece of the CurrentPage is selected from a media picker and is returning the Id to the media. I can't figure out how to get the URL to that image so I can display it in an img element. I've tried Umbraco.NiceUrl(featuredImage), featuredImage.Url, featuredImage.NiceUrl(), and the only thing I've gotten back from those is either a hash or a blank.

    How do you get a URL to media in MVC?

  • david 46 posts 81 karma points
    Feb 19, 2013 @ 13:36
    david
    0

    2 things, add umbracoFile to the Umbraco.Media call. Also, make sure that CurrentPage.FeaturedImage returns a string or an int (and not HtmlString)

     

Please Sign in or register to post replies

Write your reply to:

Draft