Copied to clipboard

Flag this post as spam?

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


  • Claushingebjerg 939 posts 2574 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 3074 posts 13631 karma points MVP 11x admin c-trib
    Oct 09, 2014 @ 10:42
    Jeavon Leopold
    0

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

  • Amalie Wowern 144 posts 273 karma points MVP c-trib
    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 939 posts 2574 karma points
    Oct 09, 2014 @ 10:46
    Claushingebjerg
    0

    If defined:
    System.int32

    If undefined:
    Umbraco.Core.Dynamics.DynamicsNull

  • Jeavon Leopold 3074 posts 13631 karma points MVP 11x 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 939 posts 2574 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 3074 posts 13631 karma points MVP 11x 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.

Please Sign in or register to post replies

Write your reply to:

Draft