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 = “”)]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What attribute do you use when class’s property can’t exceed a number of characters?

A

[MaxLength(60, ErrorMessage = “”)]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What attribute do you use when a class’s property must be between two numbers?

A

[Range(18,65, ErrorMessage = “”)]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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));
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the expression used to check on model state?

A

if (ModelState.IsValid)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly