Copied to clipboard

Flag this post as spam?

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


  • Robin Nicholl 137 posts 277 karma points
    Nov 29, 2011 @ 13:28
    Robin Nicholl
    0

    Problem with checking if property exists with Razor (uBlogsy)

    I'm simply trying to check if a page has an associated image, eg:

    @{
    if (d.HasProperty("mainImage") {
    <p>Do one thing...</p>
    } else {
    <p>Do another...</p>
    }
    }

    This one obviosuly doesn't work, but I've tried:

    if (String.IsNullOrEmpty(d.GetProperty("mainImage").ToString())==false){

    ... and a bunch of others, but noting works! Every page *has* the property, but some may not have an image uploaded (I'm using Upload data type, not Media library). In XSLT I'd simply check for an empty string being returned to indicate that no image had been uploaded for the current page...

    Any ideas?

  • Robin Nicholl 137 posts 277 karma points
    Nov 29, 2011 @ 14:55
    Robin Nicholl
    0

    OK, seems it's this:

    if @d.GetProperty("mainImage").Value.ToString(!= "" {

    Robin

  • 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