Copied to clipboard

Flag this post as spam?

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


  • James 251 posts 1169 karma points
    Jul 22, 2014 @ 13:38
    James
    0

    Checking if a field is null.

    Hello Everyone,

     

    I am trying to test to see if a user has left a certain field null. If they have then i will render one of the other fields as below:

    @if(@Umbraco.Field("Field1"){

    do this

    else{

    do this

    }

     

    I cant test using @RenderLinkIfNotEmpty. And when i look at the cheat sheet is shows .IsNull(property Alias).

     

    What is the best way for me to achieve this?

     

    Kind regards.

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jul 22, 2014 @ 13:48
    Dennis Aaen
    101

    Hi James,

    I assume that you are doing this directly in the template and not a in partial view maco.

    Try this:

    @if (string.IsNullOrWhiteSpace(CurrentPage.Field1) == false){
        do this
    }else{
        do this
    }

    If my assumption is wrong, do not hesitate to write again

    Hope this helps,

    /Dennis

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jul 22, 2014 @ 14:39
    Jeavon Leopold
    1

    How about

    @if (CurrentPage.HasValue("Field1")){
        <p>it's not null or empty</p>
    }else{ 
        <p>it's null or empty</p>
    }
    
  • Aleksey Gerasimov 31 posts 95 karma points
    Oct 07, 2016 @ 12:03
    Aleksey Gerasimov
    0

    I'm getting true even value is null. Umbraco v743

    enter image description here

  • James 251 posts 1169 karma points
    Jul 22, 2014 @ 15:30
    James
    0

    Worked great, thanks for the responses.

     

  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jul 22, 2014 @ 15:42
    Dennis Aaen
    0

    Hi James,

    That is great to hear.

    @Jeavon: I was just using the syntax from the Txt Starter Kit,

    @James, As you can see in Umbraco you can do things in several ways.

    /Dennis.

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jul 22, 2014 @ 16:19
    Jeavon Leopold
    0

    @Dennis, indeed :-)

  • 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