Copied to clipboard

Flag this post as spam?

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


  • Phani 21 posts 70 karma points
    Jun 30, 2015 @ 06:59
    Phani
    0

    NodeById, MediaById giving errors when used in umbraco templates

    HI All,

    I'm new to Umbraco 7.

    I'm trying to get descendants based on content picker property. When I tried to use NodeById and MediaById i'm getting the following error.

    Compiler Error Message: 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?)

    I managed Umbraco.Content(CurrentPage.contentpickerproperty).children in place of NodeById, but I need to get Media image Url based on Id.

    I'm using the following name spaces in template

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage @using umbraco; @using umbraco.MacroEngines; @using umbraco.macroRenderings; @using System.Web.Razor;

    Any suggestions please

    Regards, Phani

  • Casper Andersen 126 posts 508 karma points
    Jun 30, 2015 @ 07:06
    Casper Andersen
    101

    Since u are using the UmbracoTemplatePage u can do 2 things

    If you are using an Upload property you can just use

    <img src="@CurrentPage.thePropertyAlias">
    

    and if you are using a media picker you can go at it like this

    var myImage = Umbraco.Media(CurrentPage.thePropertyAlias)
    <img src="@myImage.umbracoFile" alt="@myImage.Name">
    

    Hope this helps.

    Casper

  • Phani 21 posts 70 karma points
    Jun 30, 2015 @ 07:11
    Phani
    0

    Hi Casper,

    Thanks a ton.

    It worked like a charm :)

    Regards. Phani

  • Casper Andersen 126 posts 508 karma points
    Jun 30, 2015 @ 07:13
    Casper Andersen
    0

    Your welcome.

    Would you mind marking my answer as the solution so people who have the same problem in the future can easily find the solution

  • Phani 21 posts 70 karma points
    Jun 30, 2015 @ 07:16
    Phani
    0

    HI Casper,

    I did it :)

Please Sign in or register to post replies

Write your reply to:

Draft