Model Binding and Validation
Model Binding and Validation: Model Binding and Validation: an overview, Data Annotations and ModelState, Client-Side Validation.
Updated
- Model Binding and Validation: an overview (Apprentice): Never trust what a form sends. Validate on the server every time, and in the browser too for quick feedback; ASP.NET Core does both from one set of rules on the model.
- Data Annotations and ModelState (Journeyman): Put validation rules on the model with data annotations such as [Required], [StringLength] and [Range]; check ModelState.IsValid in the action; add your own errors with AddModelError; and show the messages with validation tag helpers.
- Client-Side Validation (Apprentice): Browsers check HTML attributes such as required on their own; ASP.NET Core's validation scripts check your model's data annotations in the browser, from the data-val attributes the tag helpers write.