Copied to clipboard

Flag this post as spam?

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


  • Robin Hansen 135 posts 368 karma points
    Oct 10, 2012 @ 13:59
    Robin Hansen
    0

    Declare if dataType Upload TextString and is empty (not in use)

    I have two properties in my DocType - A textstring(focusImage1) and an Upload(focusImage1 )- both for img. links.

    In my template I'll then try to display either one of them, or a static img.

    @if (item.focusImage1 != "")
    {
    <img src="@item.focusImage1" alt="@item.Name" />
    }
    else if(item.focusImage2 != null)
    {
    <img src="@item.focusImage2" alt="@item.Name" />
    }
    else
    {
    <img src="/images/skin2012/transparent_1x1.gif" alt="" />
    }

    However I keep getting the same error: Operator '!=' cannot be applied to operands of type 'umbraco.MacroEngines.DynamicNull' and 'string' 

  • Robin Hansen 135 posts 368 karma points
    Oct 10, 2012 @ 14:25
    Robin Hansen
    0

    NM - I figuered it out myself, but feel free to use the solution - I simply added this to my if-statement:

    item.focusImage1.ToString().Trim() != ""
    item.focusImage2.ToString().Trim() != ""

     Works like a charm now... :-)

  • Kasper Dyrvig 246 posts 379 karma points
    Oct 15, 2012 @ 11:53
    Kasper Dyrvig
    0

    Hi Robin,

    You can also use String.IsNullOrWhiteSpace and/or String.IsNullOrEmpty. Like this:

    @if(!String.IsNullOrEmpty(item.focusImage1))
    {
      Do something
    }

    Is use it often.

Please Sign in or register to post replies

Write your reply to:

Draft