Data Annotations
noun
say it: “DAY-tuh an-oh-TAY-shunz” /ˈdeɪtə ˌænoʊˈteɪʃənz/
Attributes on a model's properties, such as [Required] and [Range], that set validation rules.
What is Data Annotations?
Data annotations are validation attributes on properties: [Required], [StringLength], [Range], [EmailAddress].
public sealed class SignupRequest
{
[Required, EmailAddress] public string Email { get; set; } = "";
[Required, StringLength(100, MinimumLength = 8)] public string Password { get; set; } = "";
}
In a sentence
- “With data annotations, [Required] and [Range(0, 1000)] protect the Price property.”
Level: Journeyman · More ASP.NET Core terms at this level
Updated