Reputation: 6477
I am trying to define a CSS class on a depending on a condition, in a razor view. Must be simple, but I am struggling with it.
Code so far is:
<tr class="@{if (id == 0) {@:selected} else {@:notselected}}">
Obviously missing something simple....
Thoughts appreciated....
Upvotes: 2
Views: 69
Reputation: 39501
What I do in that kind of situations is
@{
string rowClass = id == 0 ? "selected" : "notselected";
}
<tr class="@rowClass">
Anyways, if you want that inline, you could use
<tr class="@(id == 0 ? "selected" : "notselected")">
Upvotes: 2
Reputation: 38488
Try this:
<tr class="@((id == 0) ? "selected" : "notselected")">
Upvotes: 2