Table of Contents

Class DataAnnotationsModelValidatorProvider

Namespace
System.Web.Http.Validation.Providers
Assembly
System.Web.Http.dll

Represents an implementation of ModelValidatorProvider which providers validators for attributes which derive from ValidationAttribute. It also provides a validator for types which implement IValidatableObject. To support client side validation, you can either register adapters through the static methods on this class, or by having your validation attributes implement System.Web.Http.Validation.IClientValidatable. The logic to support IClientValidatable is implemented in DataAnnotationsModelValidator.

public class DataAnnotationsModelValidatorProvider : AssociatedValidatorProvider
Inheritance
DataAnnotationsModelValidatorProvider
Inherited Members

Constructors

DataAnnotationsModelValidatorProvider()

Initializes a new instance of the DataAnnotationsModelValidatorProvider class.

public DataAnnotationsModelValidatorProvider()

Methods

GetValidators(ModelMetadata, IEnumerable<ModelValidatorProvider>, IEnumerable<Attribute>)

Gets the validators for the model using the specified metadata, validator provider and attributes.

protected override IEnumerable<ModelValidator> GetValidators(ModelMetadata metadata, IEnumerable<ModelValidatorProvider> validatorProviders, IEnumerable<Attribute> attributes)

Parameters

metadata ModelMetadata

The metadata.

validatorProviders IEnumerable<ModelValidatorProvider>

The validator providers.

attributes IEnumerable<Attribute>

The attributes.

Returns

IEnumerable<ModelValidator>

The validators for the model.

RegisterAdapter(Type, Type)

Registers an adapter to provide client-side validation.

public void RegisterAdapter(Type attributeType, Type adapterType)

Parameters

attributeType Type

The type of the validation attribute.

adapterType Type

The type of the adapter.

RegisterAdapterFactory(Type, DataAnnotationsModelValidationFactory)

Registers an adapter factory for the validation provider.

public void RegisterAdapterFactory(Type attributeType, DataAnnotationsModelValidationFactory factory)

Parameters

attributeType Type

The type of the attribute.

factory DataAnnotationsModelValidationFactory

The factory that will be used to create the ModelValidator object for the specified attribute.

RegisterDefaultAdapter(Type)

Registers the default adapter.

public void RegisterDefaultAdapter(Type adapterType)

Parameters

adapterType Type

The type of the adapter.

RegisterDefaultAdapterFactory(DataAnnotationsModelValidationFactory)

Registers the default adapter factory.

public void RegisterDefaultAdapterFactory(DataAnnotationsModelValidationFactory factory)

Parameters

factory DataAnnotationsModelValidationFactory

The factory that will be used to create the ModelValidator object for the default adapter.

RegisterDefaultValidatableObjectAdapter(Type)

Registers the default adapter type for objects which implement IValidatableObject. The adapter type must derive from ModelValidator and it must contain a public constructor which takes two parameters of types ModelMetadata and HttpActionContext.

public void RegisterDefaultValidatableObjectAdapter(Type adapterType)

Parameters

adapterType Type

The type of the adapter.

RegisterDefaultValidatableObjectAdapterFactory(DataAnnotationsValidatableObjectAdapterFactory)

Registers the default adapter factory for objects which implement IValidatableObject.

public void RegisterDefaultValidatableObjectAdapterFactory(DataAnnotationsValidatableObjectAdapterFactory factory)

Parameters

factory DataAnnotationsValidatableObjectAdapterFactory

The factory.

RegisterValidatableObjectAdapter(Type, Type)

Registers an adapter type for the given modelType, which must implement IValidatableObject. The adapter type must derive from ModelValidator and it must contain a public constructor which takes two parameters of types ModelMetadata and HttpActionContext.

public void RegisterValidatableObjectAdapter(Type modelType, Type adapterType)

Parameters

modelType Type

The model type.

adapterType Type

The type of the adapter.

RegisterValidatableObjectAdapterFactory(Type, DataAnnotationsValidatableObjectAdapterFactory)

Registers an adapter factory for the given modelType, which must implement IValidatableObject.

public void RegisterValidatableObjectAdapterFactory(Type modelType, DataAnnotationsValidatableObjectAdapterFactory factory)

Parameters

modelType Type

The model type.

factory DataAnnotationsValidatableObjectAdapterFactory

The factory.