Attributes wrapped in a @
expression always get applied.
Cannot make attributes - such as disabled
- conditional on a C# expression/property.
Try the following CSHTML:
<button @{ if (false) { <text>disabled</text> } }>
I shouldn't be disabled
</button>
Button should not be disabled because the conditional evaluates to false
.
The button is actually disabled.
There is also no obvious way to add or remove the disabled
attribute through C# code without going into internal
s.
Notably, specifying CSS properties with @
expressions inside a