Copied to clipboard

Flag this post as spam?

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


  • Matt Taylor 873 posts 2086 karma points
    Jul 18, 2012 @ 14:33
    Matt Taylor
    0

    How to select the first image with Razor?

    I know this isn't really a DAMP issue but I hope someone here can help because I'm being a little thick in the head today.

    I have a DAMP property which has been populated with a number of images.
    I want to select just the first one using Razor.

    This code will loop through them and break after the first one but is a bit nasty.

    foreach (dynamic d in item.images)
    {
        var image = d.Image;
        var url = image.umbracoFile;                
        break;
     }

    Thanks,

    Matt

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Jul 18, 2012 @ 14:35
    Jeroen Breuer
    0

    I think that you can just do this:

    <img src="@item.images.Image.umbracoFile"/>

    Jeroen

  • Matt Taylor 873 posts 2086 karma points
    Jul 18, 2012 @ 17:14
    Matt Taylor
    0

    Thanks, but it doesn't seem to like that. :-(

  • Jeroen Breuer 4908 posts 12265 karma points MVP 4x admin c-trib
    Jul 18, 2012 @ 17:15
    Jeroen Breuer
    0

    Hmm do you get an exception? Maybe this:

    <img src="@item.images[0].Image.umbracoFile"/>

    Jeroen

  • Matt Taylor 873 posts 2086 karma points
    Jul 18, 2012 @ 17:28
    Matt Taylor
    0

    Yes, script error.

    That second one works though.

    Funny because I tried that approach before, just didn't get it right obviously.

    Thanks, Matt

Please Sign in or register to post replies

Write your reply to:

Draft