liveBook · Manning

Data-val-* attribute

As explained in ASP.NET Core in Action, 3e

A data-val-* attribute is an HTML attribute convention that encodes validation metadata for unobtrusive client-side validation libraries.

A data-val-* attribute encodes validation metadata on generated form fields. Client-side validation libraries read this metadata to provide immediate feedback when entered values violate DataAnnotations constraints. section 18.2.3

Generated email validation

An email field can render data-val="true", data-val-email with an error message, and data-val-required with a required-field message. jQuery Validation and its unobtrusive adapter consume these attributes when their scripts are included. section 18.2.3

How ASP.NET Core in Action, 3e covers it

How deep it goes
Explains generated validation attributes and required scripts, but does not descend into library internals or custom rule implementation.
Examples
Shows an email input with data-val-email and data-val-required metadata, plus script references for unobtrusive validation.
What it assumes
Assumes generated form fields and DataAnnotations, while demonstrating the required validation scripts and their purpose.
What you can do after
Apply it via generated form markup and validation libraries to provide immediate feedback for invalid field values.
How it connects
Connects DataAnnotations, client-side validation, jQuery, Razor Pages, Tag Helpers, and model binding.

Also explained in

Compare how 2 books explain data-val-* attribute →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ASP.NET Core in Action, 3e. The section links point to the parts of the book it draws on.