I have a required annotation on my model:
[Required(ErrorMessage = "Please choose an option")]
public bool? AnyDebts { get; set; }
I have enabled client validation in the web.config:
<appSettings>
<add key="ClientValidationEnabled" value="true" />
<add key="UnobtrusiveJavaScriptEnabled" value="true" />
</appSettings>
I have referenced the jquery scripts in my layout:
<script src="@Url.Content("~/Scripts/jquery-1.4.4.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-1.4.4.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery-ui-1.8.6.custom.min.js")" type="text/javascript"></script>
What else do I need to do to make client validation work? Server side validation is still working.
EDIT:
Ah ha!
I have found that client side validation is working.
However, specifically, I have found that model properties are not being validated client side are those annotated with custom attributes. For example:
[BooleanRequiredToBeTrue(ErrorMessage = "You must agree to the statements listed")]
public bool StatementAgree { get; set; }
The code for the attribute:
public class BooleanRequiredToBeTrueAttribute: RequiredAttribute
{
public override bool IsValid(object value)
{
return value != null && (bool)value;
}
}
Are these not validated client side anymore?