Class DataAnnotationsModelValidator
Provides a model validator.
public class DataAnnotationsModelValidator : ModelValidator
- Inheritance
-
DataAnnotationsModelValidator
- Derived
- Inherited Members
Constructors
DataAnnotationsModelValidator(ModelMetadata, ControllerContext, ValidationAttribute)
Initializes a new instance of the DataAnnotationsModelValidator class.
public DataAnnotationsModelValidator(ModelMetadata metadata, ControllerContext context, ValidationAttribute attribute)
Parameters
metadata
ModelMetadataThe metadata for the model.
context
ControllerContextThe controller context for the model.
attribute
ValidationAttributeThe validation attribute for the model.
Properties
Attribute
Gets the validation attribute for the model validator.
protected ValidationAttribute Attribute { get; }
Property Value
- ValidationAttribute
The validation attribute for the model validator.
ErrorMessage
Gets the error message for the validation failure.
protected string ErrorMessage { get; }
Property Value
- string
The error message for the validation failure.
IsRequired
Gets a value that indicates whether model validation is required.
public override bool IsRequired { get; }
Property Value
- bool
true if model validation is required; otherwise, false.
Methods
GetClientValidationRules()
Retrieves a collection of client validation rules.
public override IEnumerable<ModelClientValidationRule> GetClientValidationRules()
Returns
- IEnumerable<ModelClientValidationRule>
A collection of client validation rules.
Validate(object)
Returns a list of validation error messages for the model.
public override IEnumerable<ModelValidationResult> Validate(object container)
Parameters
container
objectThe container for the model.
Returns
- IEnumerable<ModelValidationResult>
A list of validation error messages for the model, or an empty list if no errors have occurred.