Copied to clipboard

Flag this post as spam?

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


  • Brian McNally 17 posts 105 karma points
    Jul 21, 2014 @ 22:58
    Brian McNally
    0

    Syntax on Boolean if statement in partial view template

    Just struggling with syntax on an MVC template. Seems like something straight forward but I just cant' get it to work.

    Essentially I am trying to show a section if a true/false value is true..something like this, but it's obviously not correct

          @if ("@Umbraco.Field("optInAsset") == True")
                {   
                <p>TRUE..so show this stuff</p>
                }
    else
        {
        <p>false yo</p>
        }
    
  • Dennis Aaen 4500 posts 18255 karma points admin hq c-trib
    Jul 21, 2014 @ 23:24
    Dennis Aaen
    1

    Hi Brian,

    How about this?

    @if(CurrentPage.optInAsset == "True"){
         <p>TRUE..so show this stuff</p>
    }else{
        <p>false yo</p>
    }

    Hope this helps,

    /Dennis

  • Brian McNally 17 posts 105 karma points
    Jul 21, 2014 @ 23:32
    Brian McNally
    100

    Hi Dennis, thanks for your help...that didn't seem to do it either...gave me an error:

    "Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: Operator '==' cannot be applied to operands of type 'bool' and 'string'"

    This seems to be doing the trick though:

     @if ((Umbraco.Field("optInAsset").ToString() == "True"))
                {
                <p>Show this stuff</p>
                }
                else
                {
    
                    <p> show this other stuff</p>
                }
    

    not sure if it's the best way but it's doing the trick for now..thanks

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jul 21, 2014 @ 23:32
    Jeavon Leopold
    3

    If optInAsset is a data type using the "True/False" property editor then this can be simply

    @if(CurrentPage.optInAsset){
         <p>TRUE..so show this stuff</p>
    }else{
        <p>false yo</p>
    }
    
  • sh00ks 6 posts 79 karma points
    Apr 13, 2016 @ 10:44
    sh00ks
    0

    Thanks Jeavon, that helped me out too!

    I was stuck with the classic case of over complicating!

  • Jeavon Leopold 3074 posts 13632 karma points MVP 11x admin c-trib
    Jul 21, 2014 @ 23:35
    Jeavon Leopold
    1

    Some documentation on querying can be found here

  • Brian McNally 17 posts 105 karma points
    Jul 21, 2014 @ 23:36
    Brian McNally
    0

    Hi Jeavon, Thanks!..Nice..your answer works great..

Please Sign in or register to post replies

Write your reply to:

Draft