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
metadataModelMetadataThe metadata.
validatorProvidersIEnumerable<ModelValidatorProvider>The validator providers.
attributesIEnumerable<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
RegisterAdapterFactory(Type, DataAnnotationsModelValidationFactory)
Registers an adapter factory for the validation provider.
public void RegisterAdapterFactory(Type attributeType, DataAnnotationsModelValidationFactory factory)
Parameters
attributeTypeTypeThe type of the attribute.
factoryDataAnnotationsModelValidationFactoryThe 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
adapterTypeTypeThe type of the adapter.
RegisterDefaultAdapterFactory(DataAnnotationsModelValidationFactory)
Registers the default adapter factory.
public void RegisterDefaultAdapterFactory(DataAnnotationsModelValidationFactory factory)
Parameters
factoryDataAnnotationsModelValidationFactoryThe 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
adapterTypeTypeThe type of the adapter.
RegisterDefaultValidatableObjectAdapterFactory(DataAnnotationsValidatableObjectAdapterFactory)
Registers the default adapter factory for objects which implement IValidatableObject.
public void RegisterDefaultValidatableObjectAdapterFactory(DataAnnotationsValidatableObjectAdapterFactory factory)
Parameters
factoryDataAnnotationsValidatableObjectAdapterFactoryThe 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
RegisterValidatableObjectAdapterFactory(Type, DataAnnotationsValidatableObjectAdapterFactory)
Registers an adapter factory for the given modelType, which must implement IValidatableObject.
public void RegisterValidatableObjectAdapterFactory(Type modelType, DataAnnotationsValidatableObjectAdapterFactory factory)
Parameters
modelTypeTypeThe model type.
factoryDataAnnotationsValidatableObjectAdapterFactoryThe factory.