As for as I know it seems like Microsoft are using jQuery validation attributes as default for form input attributes.
Is it possible to configure my application so if I add the Required
attribute and render my form using @Html.EditorFor(x => Model)
the form will be rendered using required
attributes instead of data-val-required
? Or am I forced to write my own EditorTemplates
for all standard types?
If you want to replace the standard
data-*
validation attributes used by ASP.NET MVC you should start by disabling unobtrusive client side validation in your web.config:This will prevent the html helpers from emitting them on your input fields.
Then you could write custom editor templates for the standard types. For example for string that would be
~/Views/Shared/editorTemplates/String.cshtml
:And that's pretty much it. Now everytime you do an
Html.EditorFor(x => x.Foo)
whereFoo
is a string property it will generate the following markup:It's also worth mentioning that if you don't want to disable unobtrusive client side validation and the
data-*
attributes for your entire application but only for a single form you could do that: