Validation Flashcards
1
Q
What attribute do you use when a class’s property can’t be null? How do you add an error message?
A
[Required(ErrorMessage = “”)]
2
Q
What attribute do you use when class’s property can’t exceed a number of characters?
A
[MaxLength(60, ErrorMessage = “”)]
3
Q
What attribute do you use when a class’s property must be between two numbers?
A
[Range(18,65, ErrorMessage = “”)]
4
Q
What attribute used on the controller applies a model state validation? How do we supress this behavior if desired?
A
[ApiController] // services.Configure( opt => { opt.SuppressModelStateInvalidFilter = true)); }
5
Q
What is the expression used to check on model state?
A
if (ModelState.IsValid)