Copied to clipboard

Flag this post as spam?

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


  • Thomas Kahn 602 posts 506 karma points
    Oct 10, 2011 @ 16:35
    Thomas Kahn
    0

    Checking for empty image crop using razor

    Hi!

    I'm using razor to display lists with blog posts and news items. Some of them have cropped images (optional) and I need a way to check if a blog post or news item has a cropped image or not.

    I use this code to display an image:

    <img src="@item.imageCrop.Find("@name""Liggande bild").url" alt="@item.name" />
    

    In this case @item is the node I get in a foreach loop. How do I check if there is a cropped image or not using razor?

    Regards,
    Thomas

  • Thomas Kahn 602 posts 506 karma points
    Oct 10, 2011 @ 16:51
    Thomas Kahn
    0

    Found something that seems to work fine:

    @if (@item.HasValue("imageCrop")) {
        <img src="@item.imageCrop.Find("@name""Liggande bild").url" alt="@item.name" />
    }

    Does anyone see a problem with this? Let me know!

    /Thomas

  • 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