9

I need to have a checkbox (for agreeing to terms) required on an MVC3 page.

Here is my model:

[Required]
[Display("I agree to the terms.")]
public bool Agreement { get; set; }

Here is my view:

@Html.CheckBoxFor(m => m.Agreement)

However, the validation isn't happening -- it allows the form to be submitted regardless.

I found that CheckBoxFor renders an additional hidden field, but I even tried rendering my own checkbox, and it still isn't getting validated:

<input type="checkbox" name="Agreement" id="Agreement" value="true" data-val="true"
    data-val-required="You must agree to the terms before proceeding." />

What am I doing wrong?

Jerad Rose
  • 15,235
  • 18
  • 82
  • 153

0 Answers0