anihilnine
anihilnine

Reputation: 127

mvc bool value in class attribute on element

I have the following:

var selected = true;
<span class="selected-@selected">text</span>

Depending on the value of selected, I am expected the following output:

<span class="selected-True">text</span>
<span class="selected-False">text</span>

But I get:

<span class="selected-class">text</span>
<span class="selected-">text</span>

Can anyone explain this?

Upvotes: 2

Views: 588

Answers (1)

WannaCSharp
WannaCSharp

Reputation: 1898

I'm not sure, but I think it's because of how razor is being smart in cases when you want to do things like

<input type="checkbox" checked="@true" />

which becomes

<input type="checkbox" checked="checked" />

that's why in your case, the value of the property became class

to fix this you could try

<span class="[email protected]()">text</span>

Upvotes: 1

Related Questions