Copied to clipboard

Flag this post as spam?

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


  • Max Davidse 16 posts 37 karma points
    May 03, 2011 @ 09:52
    Max Davidse
    0

    Check if mediaitem exists

    I've been trying to get my head around this and getting nuts trying. ;)

    I have a mediaitem that gets filled with DAMP, and am trying to check whether it exists using razor.

    To do this, I tried two different ways, but none of them worked.

    The first one I tried was:

    if (currentPage.largeBanner.mediaItem != null)

    That didn't do a thing, the error remains, which is logical in a way, as the xml contains only an empty CDATA, which is a string and no XML

    Then I tried:

    if (currentPage.largeBanner != "")

    This works, when there is in fact no mediaitem present. However, that one won't work when there actually IS one present.

    Anyone got the golden tip for me? The thing I overlooked?

    Thanks in advance!

  • nelsenlim 70 posts 71 karma points
    May 04, 2011 @ 11:30
    nelsenlim
    0

    Hi hopefully this helps

    instead of using

    if (Model.largeBanner != "")

    you can try

    if (Model.largeBanner is int)

    this will make sure that the dynamic type returned is of type int which means that the property is assigned and pointing to a mediaID

  • Glenn Franquet 18 posts 71 karma points
    May 04, 2011 @ 11:37
    Glenn Franquet
    0

    Casting first to a string and then check if the string is not empty seems to work also.
    But maybe this causes some overhead.  Not sure about that.

     if (currentPage.largeBanner.ToString() != "") 
  • nelsenlim 70 posts 71 karma points
    May 04, 2011 @ 11:46
    nelsenlim
    0

    Yep didn't think of that, that would be great as well :)
    Alright have a great day glenn.

  • Max Davidse 16 posts 37 karma points
    May 10, 2011 @ 10:00
    Max Davidse
    0

    Unfortunately, that didn't solve it either. Appearantly when it has a banner, it has a completely different structure from when it doesn't have a banner.

Please Sign in or register to post replies

Write your reply to:

Draft