Copied to clipboard

Flag this post as spam?

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


  • Martin 81 posts 246 karma points
    Mar 08, 2014 @ 17:26
    Martin
    0

    how to use Library.MediaById in Partial View

    Hi, very new to Umbraco and trying to do the following:

    In my view I have this

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @{
        Layout = "Master.cshtml";
    }
    
    <div class="item-tiles">
    
        @foreach (var child in Model.Content.Children)
        {
            Html.RenderPartial("category", child);
        }
    
    </div>
    

    and in the partial I am trying to do this:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    @{
        var image = Library.MediaById(Model.CategoryImage);
    }
    
    @image
    

    but Visual Studio doesn't like Library, am I missing a namespace or something?

  • Stan 13 posts 53 karma points
    Mar 08, 2014 @ 21:17
    Stan
    0

    hi,

    I am a newbie. I actually have a similar question but relating to displaying an image in Partial View Macros. Do hope you get a response soon. Good Luck!

  • jivan thapa 194 posts 681 karma points
    Mar 09, 2014 @ 10:56
    jivan thapa
    1

    what's about this one

    @using Umbraco.Web
    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    
    
    @try{
    
    <img src="@Umbraco.TypedMedia(@Model.Content.GetPropertyValue("CategoryImage")).Url" />
    }catch{}
    
  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Mar 11, 2014 @ 09:37
    Jeavon Leopold
    0

    You can find both MVC typed and dynamic Razor samples here

  • Charles Afford 1163 posts 1709 karma points
    Mar 11, 2014 @ 20:19
    Charles Afford
    0

    What version of umbraco are you using?  Are you using a custom model in your partial view?  You could use the MediaService which has a GetById method and return an IMedia object :)

  • Charles Afford 1163 posts 1709 karma points
    Mar 11, 2014 @ 20:20
    Charles Afford
    0

    Also to get the url you need a media object and from that object you need to the umbracoFile property

    YourMediaObject.GetProperty("umbracoFile").ToString();

  • 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