The most straight-forward way would be to bind a boolean property to the checkbox input like so:
<input type="checkbox" @bind="HasChecked" />
<button type="submit" disabled="@(!HasChecked)">Submit</button>
@code {
private bool HasChecked { get; set; }
}
@bind
ing to a checkbox with a boolean uses the checked
state of the element to determine the bound property value.
Alternatively, if you need more control, you can bind an @onchange
handler:
<input type="checkbox" @onchange="HandleCheckboxChange" />
<button type="submit" disabled="@IsDisabled">Submit</button>
@code {
private bool IsDisabled { get; set; }
private void HandleCheckboxChange(ChangeEventArgs args)
{
IsDisabled = !(args.Value is true);
}
}