ProfK
ProfK

Reputation: 51104

How do I make a radio button Yes/No field mandatory?

I have to make a Yes/No answer mandatory. The project owner wants a 'checkbox' which would involve some ugly with a tri-state checkbox, or two radio buttons. the latter seems the neatest, but I have no idea how to make it so that only one of the checkboxes must be checked. My only other idea is to stuff the checkboxes and use a dropdown.

Upvotes: 0

Views: 730

Answers (1)

Jani Hyytiäinen
Jani Hyytiäinen

Reputation: 5407

Use

[Required]
public bool? YesNo { get; set; }

In the ViewModel and make sure it's initially null.

Bool is by default false. By using nullable bool?, you set it's initial state to null.

Upvotes: 2

Related Questions