Aspnetcore: Bug - Conditional Attributes

Created on 25 Mar 2018  路  14Comments  路  Source: dotnet/aspnetcore

Title

Attributes wrapped in a @ expression always get applied.

Functional impact

Cannot make attributes - such as disabled - conditional on a C# expression/property.

Minimal repro steps

Try the following CSHTML:

<button @{ if (false) { <text>disabled</text> } }>
    I shouldn't be disabled
</button>

Expected result

Button should not be disabled because the conditional evaluates to false.

Actual result

The button is actually disabled.

Further technical details

There is also no obvious way to add or remove the disabled attribute through C# code without going into internals.

Notably, specifying CSS properties with @ expressions inside a