我有一个MVC应用程序,其模型属性如下:
[Display(Name = "Terms and Conditions")]
[Range(typeof(bool), "true", "true", ErrorMessage = "You gotta tick the box!")]
public bool AcceptTerms { get; set; }
我正在尝试添加验证以在未单击时显示消息,但无论是否单击它都会显示错误消息,因此我无法传递此表单,视图如下:
<div class="form-group">
@Html.Label("Accept Terms", htmlAttributes: new { @class = "control-label col-md-4" })
<div class="col-md-8">
<div class="checkbox">
@Html.EditorFor(x => x.AcceptTerms)
@Html.ValidationMessageFor(x => x.AcceptTerms)
</div>
</div>
</div>
我在这里做错了什么?