Table of Contents

Class DefaultModelBinder

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

Maps a browser request to a data object. This class provides a concrete implementation of a model binder.

public class DefaultModelBinder : IModelBinder
Inheritance
DefaultModelBinder
Implements
Inherited Members

Constructors

DefaultModelBinder()

Initializes a new instance of the DefaultModelBinder class.

public DefaultModelBinder()

Properties

Binders

Gets or sets the model binders for the application.

protected ModelBinderDictionary Binders { get; set; }

Property Value

ModelBinderDictionary

The model binders for the application.

ResourceClassKey

Gets or sets the name of the resource file (class key) that contains localized string values.

public static string ResourceClassKey { get; set; }

Property Value

string

The name of the resource file (class key).

Methods

BindModel(ControllerContext, ModelBindingContext)

Binds the model by using the specified controller context and binding context.

public virtual object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)

Parameters

controllerContext ControllerContext

The context within which the controller operates. The context information includes the controller, HTTP content, request context, and route data.

bindingContext ModelBindingContext

The context within which the model is bound. The context includes information such as the model object, model name, model type, property filter, and value provider.

Returns

object

The bound object.

Exceptions

ArgumentNullException

The bindingContext parameter is null.

BindProperty(ControllerContext, ModelBindingContext, PropertyDescriptor)

Binds the specified property by using the specified controller context and binding context and the specified property descriptor.

protected virtual void BindProperty(ControllerContext controllerContext, ModelBindingContext bindingContext, PropertyDescriptor propertyDescriptor)

Parameters

controllerContext ControllerContext

The context within which the controller operates. The context information includes the controller, HTTP content, request context, and route data.

bindingContext ModelBindingContext

The context within which the model is bound. The context includes information such as the model object, model name, model type, property filter, and value provider.

propertyDescriptor PropertyDescriptor

Describes a property to be bound. The descriptor provides information such as the component type, property type, and property value. It also provides methods to get or set the property value.

CreateModel(ControllerContext, ModelBindingContext, Type)

Creates the specified model type by using the specified controller context and binding context.

protected virtual object CreateModel(ControllerContext controllerContext, ModelBindingContext bindingContext, Type modelType)

Parameters

controllerContext ControllerContext

The context within which the controller operates. The context information includes the controller, HTTP content, request context, and route data.

bindingContext ModelBindingContext

The context within which the model is bound. The context includes information such as the model object, model name, model type, property filter, and value provider.

modelType Type

The type of the model object to return.

Returns

object

A data object of the specified type.

CreateSubIndexName(string, int)

Creates an index (a subindex) based on a category of components that make up a larger index, where the specified index value is an integer.

protected static string CreateSubIndexName(string prefix, int index)

Parameters

prefix string

The prefix for the subindex.

index int

The index value.

Returns

string

The name of the subindex.

CreateSubIndexName(string, string)

Creates an index (a subindex) based on a category of components that make up a larger index, where the specified index value is a string.

protected static string CreateSubIndexName(string prefix, string index)

Parameters

prefix string

The prefix for the subindex.

index string

The index value.

Returns

string

The name of the subindex.

CreateSubPropertyName(string, string)

Creates the name of the subproperty by using the specified prefix and property name.

protected static string CreateSubPropertyName(string prefix, string propertyName)

Parameters

prefix string

The prefix for the subproperty.

propertyName string

The name of the property.

Returns

string

The name of the subproperty.

GetFilteredModelProperties(ControllerContext, ModelBindingContext)

Returns a set of properties that match the property filter restrictions that are established by the specified binding context.

protected IEnumerable<PropertyDescriptor> GetFilteredModelProperties(ControllerContext controllerContext, ModelBindingContext bindingContext)

Parameters

controllerContext ControllerContext

The context within which the controller operates. The context information includes the controller, HTTP content, request context, and route data.

bindingContext ModelBindingContext

The context within which the model is bound. The context includes information such as the model object, model name, model type, property filter, and value provider.

Returns

IEnumerable<PropertyDescriptor>

An enumerable set of property descriptors.

GetModelProperties(ControllerContext, ModelBindingContext)

Returns the properties of the model by using the specified controller context and binding context.

protected virtual PropertyDescriptorCollection GetModelProperties(ControllerContext controllerContext, ModelBindingContext bindingContext)

Parameters

controllerContext ControllerContext

The context within which the controller operates. The context information includes the controller, HTTP content, request context, and route data.

bindingContext ModelBindingContext

The context within which the model is bound. The context includes information such as the model object, model name, model type, property filter, and value provider.

Returns

PropertyDescriptorCollection

A collection of property descriptors.

GetPropertyValue(ControllerContext, ModelBindingContext, PropertyDescriptor, IModelBinder)

Returns the value of a property using the specified controller context, binding context, property descriptor, and property binder.

protected virtual object GetPropertyValue(ControllerContext controllerContext, ModelBindingContext bindingContext, PropertyDescriptor propertyDescriptor, IModelBinder propertyBinder)

Parameters

controllerContext ControllerContext

The context within which the controller operates. The context information includes the controller, HTTP content, request context, and route data.

bindingContext ModelBindingContext

The context within which the model is bound. The context includes information such as the model object, model name, model type, property filter, and value provider.

propertyDescriptor PropertyDescriptor

The descriptor for the property to access. The descriptor provides information such as the component type, property type, and property value. It also provides methods to get or set the property value.

propertyBinder IModelBinder

An object that provides a way to bind the property.

Returns

object

An object that represents the property value.

GetTypeDescriptor(ControllerContext, ModelBindingContext)

Returns the descriptor object for a type that is specified by its controller context and binding context.

protected virtual ICustomTypeDescriptor GetTypeDescriptor(ControllerContext controllerContext, ModelBindingContext bindingContext)

Parameters

controllerContext ControllerContext

The context within which the controller operates. The context information includes the controller, HTTP content, request context, and route data.

bindingContext ModelBindingContext

The context within which the model is bound. The context includes information such as the model object, model name, model type, property filter, and value provider.

Returns

ICustomTypeDescriptor

A custom type descriptor object.

IsModelValid(ModelBindingContext)

Determines whether a data model is valid for the specified binding context.

protected static bool IsModelValid(ModelBindingContext bindingContext)

Parameters

bindingContext ModelBindingContext

The context within which the model is bound. The context includes information such as the model object, model name, model type, property filter, and value provider.

Returns

bool

true if the model is valid; otherwise, false.

Exceptions

ArgumentNullException

The bindingContext parameter is null.

OnModelUpdated(ControllerContext, ModelBindingContext)

Called when the model is updated.

protected virtual void OnModelUpdated(ControllerContext controllerContext, ModelBindingContext bindingContext)

Parameters

controllerContext ControllerContext

The context within which the controller operates. The context information includes the controller, HTTP content, request context, and route data.

bindingContext ModelBindingContext

The context within which the model is bound. The context includes information such as the model object, model name, model type, property filter, and value provider.

OnModelUpdating(ControllerContext, ModelBindingContext)

Called when the model is updating.

protected virtual bool OnModelUpdating(ControllerContext controllerContext, ModelBindingContext bindingContext)

Parameters

controllerContext ControllerContext

The context within which the controller operates. The context information includes the controller, HTTP content, request context, and route data.

bindingContext ModelBindingContext

The context within which the model is bound. The context includes information such as the model object, model name, model type, property filter, and value provider.

Returns

bool

true if the model is updating; otherwise, false.

OnPropertyValidated(ControllerContext, ModelBindingContext, PropertyDescriptor, object)

Called when the specified property is validated.

protected virtual void OnPropertyValidated(ControllerContext controllerContext, ModelBindingContext bindingContext, PropertyDescriptor propertyDescriptor, object value)

Parameters

controllerContext ControllerContext

The context within which the controller operates. The context information includes the controller, HTTP content, request context, and route data.

bindingContext ModelBindingContext

The context within which the model is bound. The context includes information such as the model object, model name, model type, property filter, and value provider.

propertyDescriptor PropertyDescriptor

Describes a property to be validated. The descriptor provides information such as the component type, property type, and property value. It also provides methods to get or set the property value.

value object

The value to set for the property.

OnPropertyValidating(ControllerContext, ModelBindingContext, PropertyDescriptor, object)

Called when the specified property is validating.

protected virtual bool OnPropertyValidating(ControllerContext controllerContext, ModelBindingContext bindingContext, PropertyDescriptor propertyDescriptor, object value)

Parameters

controllerContext ControllerContext

The context within which the controller operates. The context information includes the controller, HTTP content, request context, and route data.

bindingContext ModelBindingContext

The context within which the model is bound. The context includes information such as the model object, model name, model type, property filter, and value provider.

propertyDescriptor PropertyDescriptor

Describes a property being validated. The descriptor provides information such as component type, property type, and property value. It also provides methods to get or set the property value.

value object

The value to set for the property.

Returns

bool

true if the property is validating; otherwise, false.

SetProperty(ControllerContext, ModelBindingContext, PropertyDescriptor, object)

Sets the specified property by using the specified controller context, binding context, and property value.

protected virtual void SetProperty(ControllerContext controllerContext, ModelBindingContext bindingContext, PropertyDescriptor propertyDescriptor, object value)

Parameters

controllerContext ControllerContext

The context within which the controller operates. The context information includes the controller, HTTP content, request context, and route data.

bindingContext ModelBindingContext

The context within which the model is bound. The context includes information such as the model object, model name, model type, property filter, and value provider.

propertyDescriptor PropertyDescriptor

Describes a property to be set. The descriptor provides information such as the component type, property type, and property value. It also provides methods to get or set the property value.

value object

The value to set for the property.