Copied to clipboard

Flag this post as spam?

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


  • Martin McMahon 69 posts 101 karma points
    Mar 31, 2012 @ 17:51
    Martin McMahon
    0

    CSS class based on property

    I have a true/false property and need to add a class to a table cell based on this being true.

    The property is productOne and if it's been set to True I need

    <td class ="tick"></td>

    Otherwise

    <td></td>

    However no matter what I've tried I just can't figure out how to do this. Any ideas? Thanks.

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Mar 31, 2012 @ 18:07
    Jan Skovgaard
    0

    Hi Martin

    What version of Umbraco are you trying to achieve the above on? And do you mind sharing the razor code you have been trying to get to work?

    /Jan

  • Martin McMahon 69 posts 101 karma points
    Mar 31, 2012 @ 19:02
    Martin McMahon
    0

    Hi, I'm using v 5.02

    I tried various things e.g.

     

    <td class="@(Umbraco.Field("productOne") == "True" ? "tick" : "")"></td>

    Compiler Error Message: CS0019: Operator '==' cannot be applied to operands of type 'System.Web.IHtmlString' and 'string'

    <td class="@(Umbraco.Field("productOne").ToString == "True" ? "tick" : "")"></td>

    Compiler Error Message: CS0019: Operator '==' cannot be applied to operands of type 'method group' and 'string'

    @if("productOne  == True") 
    <text><td class="class"></td></text>
    }
    else
    {
    <td></td>
    }

     

    Compiler Error Message: CS0029: Cannot implicitly convert type 'string' to 'bool'

     

    Cheers

  • Martin McMahon 69 posts 101 karma points
    Apr 01, 2012 @ 23:17
    Martin McMahon
    1

    Got it working. My second try should obviously have been - 

    <td class ="@(Umbraco.Field("productOne").ToString()=="True" ? "tick" : "")"></td>
  • 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