Copied to clipboard

Flag this post as spam?

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


  • Matthew Hunt 13 posts 35 karma points
    Nov 06, 2012 @ 17:38
    Matthew Hunt
    0

    Umbraco 4.10 Razor - Getting image from media picker

    Hi I've just downloaded and installed Ubmraco 4.10. So far so good, my only issue is how do we get media?

    I've chosen an image with a media picker and now want to show that in my Razor view. I tried:

    @Umbraco.Media(production.GetPropertyValue<int>("Thumbnail")).NiceUrl()
    

    but with no luck

  • Fuji Kusaka 2203 posts 4220 karma points
    Nov 07, 2012 @ 05:41
    Fuji Kusaka
    0

    Hi Matthew,

    Try something like,

    @{
    var img = Model.MediaById(Model.Thumbnail);
    // you could also make a check to see if an image has been choose
    if(!String.IsNullOrEmpty(@Model.Thumbnail)){
    <a href="@img.Url">@img.Name</a>
    }
    }
  • Brooke 13 posts 34 karma points
    Nov 08, 2012 @ 16:13
    Brooke
    1

    Hi Fuji,

    I received the following below for the following line:

    var img =Model.MediaById(Model.Thumbnail);

    CS1061: 'Umbraco.Web.Models.RenderModel' does not contain a definition for 'MediaById' and no extension method 'MediaById' accepting a first argument of type 'Umbraco.Web.Models.RenderModel' could be found (are you missing a using directive or an assembly reference?)

    This error occured for an MVC template in Umbraco 4.10beta

  • Brooke 13 posts 34 karma points
    Nov 09, 2012 @ 12:25
    Brooke
    0

    For anyone who is interested, I have solved this in another post.

    http://our.umbraco.org/forum/core/general/35714-Fetching-a-media-item-properties-?p=0

     

  • Sahan Rodrigo 25 posts 97 karma points
    Nov 16, 2012 @ 00:08
    Sahan Rodrigo
    1

     

    Try this inline razor macro to display a single image...
    <umbraco:Macro runat="server" language="cshtml"> 
    <img src="@Library.MediaById(Model.YourPropertyAlias).umbracoFile" alt"@Library.MediaById(Model.YourPropertyAlias).nodeName">
    </umbraco:Macro>
    Thanks, Sahan
Please Sign in or register to post replies

Write your reply to:

Draft