Table of Contents

Class DataAnnotationsModelValidator

Namespace
System.Web.Mvc
Assembly
System.Web.Mvc.dll

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 ModelMetadata

The metadata for the model.

context ControllerContext

The controller context for the model.

attribute ValidationAttribute

The 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 object

The 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.