Copied to clipboard

Flag this post as spam?

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


  • Lars 66 posts 136 karma points
    Feb 24, 2015 @ 13:55
    Lars
    0

    Get image by MediaPicker not working

    Hi. I am trying in Umbraco 7 in Razor to get an image by ImagePicker.

    I have read the article of https://our.umbraco.org/DOCUMENTATION/Using-Umbraco/Backoffice-Overview/Property-Editors/Built-in-Property-Editors/Media-Picker and I am trying with:

     @{                                                             
        var selectedMedia3 = @Umbraco.Field("myPictyre");
          <img src="@selectedMedia3.umbracoFile" width="@selectedMedia3.umbracoWidth"    height="@selectedMedia3.umbracoHeight" alt="@selectedMedia3.Name"/>
        } 

    I am getting the error: "'System.Web.IHtmlString' does not contain a definition for 'umbracoFile' and no method for  'umbracoFile' was found that supplies a first argument of the type 'System.Web.IHtmlString' (are you missing a  'using'-directive or an assembly reference?).

    Can someone tell me what assemply reference I need for this or maybe there is a better way to show the image.

    Thank you in advance
    //Lars

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Feb 24, 2015 @ 14:01
    Dennis Aaen
    100

    Hi Lars,

    Try this code instead:

    @{ 
        if (CurrentPage.HasValue("myPictyre")){
            var dynamicMediaItem = Umbraco.Media(CurrentPage.myPictyre);
            <img src="@dynamicMediaItem.umbracoFile" alt="@dynamicMediaItem.Name" width="@dynamicMediaItem.umbracoWidth" height="@dynamicMediaItem.umbracoHeight"/>
        }
    }

    You can find the documentation here: https://our.umbraco.org/documentation/Using-Umbraco/Backoffice-Overview/Property-Editors/Built-in-Property-Editors/Media-Picker use only the dynamic or strongly typed razor examples. Not the dynamic node razor this is deprecated.

    Hope this helps,

    /Dennis

  • Lars 66 posts 136 karma points
    Feb 24, 2015 @ 14:13
    Lars
    0

    Hi Dennis

    Thank you for

    1. A quick reply
    2. Code that works
    3. Maybe an explanation why it didn't work

    Great, a big thanks from here :-)

    //Lars

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Feb 24, 2015 @ 14:16
    Dennis Aaen
    0

    Hi Lars,

    You are welcome. Happy that I could help you - Please remember to mark the question as solve, you do this by click the green tick in the left side, on the post that gives you the solution.

    /Dennis

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Feb 24, 2015 @ 14:34
    Jan Skovgaard
    0

    Hi Lars

    An explanation to why the code you posted did not work...

    @Umbraco.Field("MyPicture") does not return the image but the id of the image, which you can then use to fetch the correct image. So if you just write out that piece of code you will get something like 1210, which is the id.

    By using the built in Umbraco.Media method the magic happens behind the scenes :)

    Hope this makes sense.

    /Jan

  • Lars 66 posts 136 karma points
    Feb 24, 2015 @ 15:03
    Lars
    0

    Hi Jan

    Thank you for your answer. I knew about the media method returning the ID. But I am confused about depreciated Razor in Umbraco 7 and how to work around it (strongly typed, new documentation or ???)

    //Lars

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Feb 24, 2015 @ 15:08
    Dennis Aaen
    0

    Hi Lars,

    You can find the documentation for the bult in property editors in Umbraco 7 here: https://our.umbraco.org/documentation/using-umbraco/backoffice-overview/property-editors/Built-in-Property-Editors-v7/

    Hope this helps,

    /Dennis

  • Lars 66 posts 136 karma points
    Feb 25, 2015 @ 10:33
    Lars
    0

    Hi Dennis

    That helps a lot. Thank you very much for your help :-)

    // Lars

Please Sign in or register to post replies

Write your reply to:

Draft