I have an MVC application with a model property as follows:
[Display(Name = "Terms and Conditions")]
[Range(typeof(bool), "true", "true", ErrorMessage = "You gotta tick the box!")]
public bool AcceptTerms { get; set; }
I am trying to add validation to display a message when it is not clicked but regardless of whether it is clicked or not the error message always displays and so I cannot pass this form, view is as follows:
<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>
What am I doing wrong here?