3

I want to do something like this:

View

<td class="[email protected]">
      @Model.Description
</td>

CSS

<style type="text/css">
    .status_True
    {
        background-color: Red;
    }
    .status_False
    {
        background-color: Green;
    }
</style>

@Model.IsActive is return True or False. Of course this code is not working.

Html output of class is : class="[email protected]"

My expected output is : class="status_True"

Is this possible to do something like this logic? If is possible, How can I do? Or another way to change css class? There may be different ways.

Thanks.

1
  • You can do this with CSS, maybe this article will help you. Commented Aug 29, 2012 at 14:06

1 Answer 1

9

Razor syntax takes some getting used to. Use parenthesis to get the actual property value:

<td class="status_@(Model.IsActive)">

Here's a quick reference from Phil Haack

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.