December 2019
Intermediate to advanced
598 pages
12h 21m
English
We can add validation to a model by adding validation attributes to properties in the model that specify rules that should be adhered to. Let's add validation to the request for posting a question:
using System.ComponentModel.DataAnnotations;
This namespace gives us access to the validation attributes.
[Required]public string Title { get; set; }
The Required attribute will check that the Title property is not an empty string or null.
Read now
Unlock full access