Copied to clipboard

Flag this post as spam?

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


  • Claushingebjerg 886 posts 2415 karma points
    Oct 09, 2014 @ 10:29
    Claushingebjerg
    0

    Get an image... Should be simple..

    Im trying to show an image. simple.. but it defies me..

    @page.logo

    Gets me the image id (1231)

    @Umbraco.Media(1231).Url

    Gets me the image url

    @Umbraco.Media(page.logo).Url or 
    @Umbraco.Media(@page.logo).Url

    Gives me an error... Why?

  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Oct 09, 2014 @ 10:42
    Jeavon Leopold
    0

    Can you try @page.logo.GetType() to see what it returns?

  • Amalie Wowern 113 posts 220 karma points
    Oct 09, 2014 @ 10:45
    Amalie Wowern
    0

    Maybe

    @Umbraco.Media(Convert.toInt32(page.logo)).Url

    Or

    @Umbraco.Media(Convert.toInt32(page.logo.ToString())).Url

  • Claushingebjerg 886 posts 2415 karma points
    Oct 09, 2014 @ 10:46
    Claushingebjerg
    0

    If defined:
    System.int32

    If undefined:
    Umbraco.Core.Dynamics.DynamicsNull

  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Oct 09, 2014 @ 10:48
    Jeavon Leopold
    100

    Of so you need a test then

    if (page.HasValue("logo")){
    @Umbraco.Media(page.logo).Url
    }
    
  • Claushingebjerg 886 posts 2415 karma points
    Oct 09, 2014 @ 10:52
    Claushingebjerg
    0

    Of course, the check...

    And i needed an @ in this context

    @if (page.HasValue("logo")){
    <img src="@Umbraco.Media(page.logo).Url" />
    }

    Thanks :)

  • Jeavon Leopold 3008 posts 13221 karma points MVP 7x admin c-trib
    Oct 09, 2014 @ 10:54
    Jeavon Leopold
    0

    Np, you can't pass in that DynamicNull which is why it was throwing, the check stops that.

  • 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