At this point I believe the following is a complete set of requirements:
- Create a form with
Html.BeginForm
- Turn on
ClientValidationEnabled
- Turn on
UnobtrusiveJavaScriptEnabled
- Set appropriate validation attributes on the model’s properties (not fields)
- If the Html Helpers being used to create the form elements are not on the same form as the
Html.BeginForm
call, use a relevant workaround (see workaround 1 and workaround 2) - Include
jquery
,jquery.validate.js
, andjquery.validate.unobtrusive.js
files, in that order - Verify that the unobtrusive validation attributes are present in the HTML
- If using custom validators:
- ensure that they are added to
jQuery.validator.unobtrusive.adapters
- ensure that they are added to the jQuery validation plugin by calling
jQuery.validator.addMethod
. - ensure that the above happen before
$(document).ready()
as at that point it’s too late
- ensure that they are added to
- Call
jQuery.validator.unobtrusive.parse
orjQuery.validator.unobtrusive.parseElement
on elements added dynamically after the initial page load.