Field Validation HTML
The Field Validation HTML is markup that acts as both a placeholder to display any client-side validation messages for a particular Field as well as displaying any server-side validation messages for that Field. The Field Validation HTML can be:
- Specified manually
- Created by a Field Generator based on the metadata of the model property being displayed and the Field Configuration specified when it's:
- Displayed as part of a Field
- Output directly from the Form
Outputting directly from the Form
To use a Field Generator to output the HTML for a standalone Field Validation HTML you can use the <field-validation />
tag, e.g.:
<field-validation for="SomeField" />
<field-validation for="SomeField" fluent-config='c => c.ChainFieldConfigurationMethodsHere()' />
<field-validation for="SomeField" add-validation-class="validation" />
To see the different configuration options check out field configuration.
Default HTML
The HTML for the Field Validation HTML is the same as calling:
@Html.ValidationMessageFor(m => m.SomeField, new { @class = %validationClasses% })
or
<span asp-validation-for="SomeField" class="%validationClasses%"></span>
The default Field Generator ignores all properties on the Field Configuration when generating the Field Validation HTML apart from the ValidationClasses
property, which you can set using the AddValidationClass
method.