Validation attribute
A validation attribute is metadata attached to a class or member that applies a rule for determining whether data satisfies specified requirements.
Building Web APIs with ASP.NET Core
A custom validation attribute is an application-defined attribute that implements a domain-specific input-validation rule.
- How it is used
- Guards client-supplied sort strings before a board-game API uses them in dynamic ordering.
- How deep it goes
- Works through an attribute subclass, its validation result, parameter placement, and OpenAPI filters.
- Examples
- Uses sort-direction and sort-column validators on a GET endpoint, then moves them into a request DTO.
- What you can do after
- Build it from scratch by subclassing ValidationAttribute, applying the rule to an input, and checking its error response.
Read how Building Web APIs with ASP.NET Core explains validation attribute →
ASP.NET Core in Action, 3e
A custom validation attribute is an application-defined attribute that implements a specialized validation rule, typically by deriving from ValidationAttribute.
- How it is used
- Extends property-level DataAnnotations validation with domain-specific rules in Razor Pages and MVC binding models.
- How deep it goes
- Explains derivation, IsValid, error results, reuse, and service lookup, while deferring complex cross-property business rules.
- Examples
- Uses a currency converter that accepts only GBP, USD, EUR, or CAD and rejects an invalid value such as £$%.
- What you can do after
- Build it from scratch by defining, applying, and testing a reusable ValidationAttribute for application-specific property rules.
Read how ASP.NET Core in Action, 3e explains validation attribute →
Pro ASP.NET Core 7, Tenth Edition
A custom validation attribute is an application-defined .NET attribute derived from ValidationAttribute that supplies validation logic for model data.
- How it is used
- Centralizes application-specific model rules so bound data receives consistent validation across controllers and Razor Pages.
- How deep it goes
- Works through property- and model-level IsValid implementations, service access, attribute placement, and a Razor Pages error-display workaround.
- Examples
- Uses a database-backed primary-key check and a class-level name-and-price rule on a product form.
- What you can do after
- Build it from scratch to replace duplicated controller and Razor Page checks with reusable property- or model-level validation.
Read how Pro ASP.NET Core 7, Tenth Edition explains validation attribute →
What to know first
- model bindingModel binding is the process of locating incoming data, converting it to appropriate types, and assigning it to application objects or handler parameters.
Related concepts
- Range attributeincludes · The Range attribute is a validation attribute that constrains a value to a specified minimum and maximum.
- RequiredAttributeincludes · RequiredAttribute is a .NET data-annotation validation attribute that requires an annotated property or field to have a supplied, non-null value.
- client-side validationcontrasts with · Client-side validation is the checking of data in client software before it is sent to a server or otherwise processed remotely.
- IValidatableObjectalternative to · IValidatableObject is a .NET interface that lets an object perform validation involving its own values and relationships and return validation results.
- RegularExpression attributealternative to · RegularExpressionAttribute is a .NET validation attribute that accepts a value only when it matches a specified regular expression.
Questions about validation attribute
What is validation attribute?
A validation attribute is metadata attached to a class or member that applies a rule for determining whether data satisfies specified requirements.
Which Manning books explain validation attribute?
Building Web APIs with ASP.NET Core, ASP.NET Core in Action, 3e and Pro ASP.NET Core 7, Tenth Edition.
What should I know before learning validation attribute?
Manning books that teach validation attribute usually introduce model binding first.
What is the difference between validation attribute and client-side validation?
A validation attribute is metadata attached to a class or member that applies a rule for determining whether data satisfies specified requirements. Client-side validation is the checking of data in client software before it is sent to a server or otherwise processed remotely.
What kinds of validation attribute are there?
Kinds of validation attribute include Range attribute and RequiredAttribute.
What is validation attribute a kind of?
Validation attribute is a kind of ValidationAttribute. ValidationAttribute is a .NET base attribute class for declaring and performing validation rules on types or members.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.


