You have to use the binding in a ternary operator to achieve this.
<div class="menu @(IsOpen ? "open" : "")"></div>
<button @onclick="@AddClass">Add Class</button>
@code {
private bool IsOpen { get; set; } = false;
private void AddClass()
{
IsOpen = !IsOpen;
}
}
Share with