ModelBindingHelper Class

Syntax

public class ModelBindingHelper

GitHub

View on GitHub

class Microsoft.AspNet.Mvc.ModelBindingHelper

Methods

ClearValidationStateForModel(System.Type, Microsoft.AspNet.Mvc.ModelBinding.ModelStateDictionary, Microsoft.AspNet.Mvc.ModelBinding.IModelMetadataProvider, System.String)

Clears [Microsoft.AspNet.Mvc.ModelBinding.ModelStateDictionary]() entries for [Microsoft.AspNet.Mvc.ModelBinding.ModelMetadata]().

Arguments:
public static void ClearValidationStateForModel(Type modelType, ModelStateDictionary modelstate, IModelMetadataProvider metadataProvider, string modelKey)
ConvertValuesToCollectionType<T>(System.Type, System.Collections.Generic.IList<T>)
Arguments:
  • modelType (System.Type) –
  • values (System.Collections.Generic.IList{{T}}) –
Return type:

System.Object

public static object ConvertValuesToCollectionType<T>(Type modelType, IList<T> values)
Microsoft.AspNet.Mvc.ModelBindingHelper.GetIncludePredicateExpression<TModel>(System.String, System.Linq.Expressions.Expression<System.Func<TModel, System.Object>>[])

Creates an expression for a predicate to limit the set of properties used in model binding.

Arguments:
  • prefix (System.String) – The model prefix.
  • expressions (System.Linq.Expressions.Expression{System.Func{{TModel},System.Object}}[]) – Expressions identifying the properties to allow for binding.
Return type:

System.Linq.Expressions.Expression{System.Func{Microsoft.AspNet.Mvc.ModelBinding.ModelBindingContext,System.String,System.Boolean}}

Returns:

An expression which can be used with [Microsoft.AspNet.Mvc.ModelBinding.IPropertyBindingPredicateProvider]().

public static Expression<Func<ModelBindingContext, string, bool>> GetIncludePredicateExpression<TModel>(string prefix, Expression<Func<TModel, object>>[] expressions)
TryUpdateModelAsync(System.Object, System.Type, System.String, HttpContext, Microsoft.AspNet.Mvc.ModelBinding.ModelStateDictionary, Microsoft.AspNet.Mvc.ModelBinding.IModelMetadataProvider, Microsoft.AspNet.Mvc.ModelBinding.IModelBinder, Microsoft.AspNet.Mvc.ModelBinding.IValueProvider, System.Collections.Generic.IList<Microsoft.AspNet.Mvc.IInputFormatter>, Microsoft.AspNet.Mvc.ModelBinding.Validation.IObjectModelValidator, Microsoft.AspNet.Mvc.ModelBinding.Validation.IModelValidatorProvider)

Updates the specified <paramref name=”model” /> instance using the specified <paramref name=”modelBinder” /> and the specified <paramref name=”valueProvider” /> and executes validation using the specified

<paramref name=”validatorProvider” />.

Arguments:
Return type:

System.Threading.Tasks.Task{System.Boolean}

Returns:

A [System.Threading.Tasks.Task]() that on completion returns <c>true</c> if the update is successful

public static Task<bool> TryUpdateModelAsync(object model, Type modelType, string prefix, HttpContext httpContext, ModelStateDictionary modelState, IModelMetadataProvider metadataProvider, IModelBinder modelBinder, IValueProvider valueProvider, IList<IInputFormatter> inputFormatters, IObjectModelValidator objectModelValidator, IModelValidatorProvider validatorProvider)
TryUpdateModelAsync(System.Object, System.Type, System.String, HttpContext, Microsoft.AspNet.Mvc.ModelBinding.ModelStateDictionary, Microsoft.AspNet.Mvc.ModelBinding.IModelMetadataProvider, Microsoft.AspNet.Mvc.ModelBinding.IModelBinder, Microsoft.AspNet.Mvc.ModelBinding.IValueProvider, System.Collections.Generic.IList<Microsoft.AspNet.Mvc.IInputFormatter>, Microsoft.AspNet.Mvc.ModelBinding.Validation.IObjectModelValidator, Microsoft.AspNet.Mvc.ModelBinding.Validation.IModelValidatorProvider, System.Func<Microsoft.AspNet.Mvc.ModelBinding.ModelBindingContext, System.String, System.Boolean>)

Updates the specified <paramref name=”model” /> instance using the specified <paramref name=”modelBinder” /> and the specified <paramref name=”valueProvider” /> and executes validation using the specified

<paramref name=”validatorProvider” />.

Arguments:
  • model (System.Object) – The model instance to update and validate.
  • modelType (System.Type) – The type of model instance to update and validate.
  • prefix (System.String) – The prefix to use when looking up values in the <paramref name=”valueProvider” />.
  • httpContext (HttpContext) – The @!:HttpContext- for the current executing request.
  • modelState (Microsoft.AspNet.Mvc.ModelBinding.ModelStateDictionary) – The [Microsoft.AspNet.Mvc.ModelBinding.ModelStateDictionary]() used for maintaining state and results of model-binding validation.
  • metadataProvider (Microsoft.AspNet.Mvc.ModelBinding.IModelMetadataProvider) – The provider used for reading metadata for the model type.
  • modelBinder (Microsoft.AspNet.Mvc.ModelBinding.IModelBinder) – The [Microsoft.AspNet.Mvc.ModelBinding.IModelBinder]() used for binding.
  • valueProvider (Microsoft.AspNet.Mvc.ModelBinding.IValueProvider) – The [Microsoft.AspNet.Mvc.ModelBinding.IValueProvider]() used for looking up values.
  • inputFormatters (System.Collections.Generic.IList{Microsoft.AspNet.Mvc.IInputFormatter}) – The set of [Microsoft.AspNet.Mvc.IInputFormatter]() instances for deserializing the body.
  • objectModelValidator (Microsoft.AspNet.Mvc.ModelBinding.Validation.IObjectModelValidator) – The [Microsoft.AspNet.Mvc.ModelBinding.Validation.IObjectModelValidator](Microsoft.AspNet.Mvc.ModelBinding.Validation.IObjectModelValidator.yml) used for validating the bound values.
  • validatorProvider (Microsoft.AspNet.Mvc.ModelBinding.Validation.IModelValidatorProvider) – The [Microsoft.AspNet.Mvc.ModelBinding.Validation.IModelValidatorProvider]() used for executing validation on the model instance.
  • predicate (System.Func{Microsoft.AspNet.Mvc.ModelBinding.ModelBindingContext,System.String,System.Boolean}) – A predicate which can be used to filter properties(for inclusion/exclusion) at runtime.
Return type:

System.Threading.Tasks.Task{System.Boolean}

Returns:

A [System.Threading.Tasks.Task]() that on completion returns <c>true</c> if the update is successful

public static Task<bool> TryUpdateModelAsync(object model, Type modelType, string prefix, HttpContext httpContext, ModelStateDictionary modelState, IModelMetadataProvider metadataProvider, IModelBinder modelBinder, IValueProvider valueProvider, IList<IInputFormatter> inputFormatters, IObjectModelValidator objectModelValidator, IModelValidatorProvider validatorProvider, Func<ModelBindingContext, string, bool> predicate)
Microsoft.AspNet.Mvc.ModelBindingHelper.TryUpdateModelAsync<TModel>(TModel, System.String, HttpContext, Microsoft.AspNet.Mvc.ModelBinding.ModelStateDictionary, Microsoft.AspNet.Mvc.ModelBinding.IModelMetadataProvider, Microsoft.AspNet.Mvc.ModelBinding.IModelBinder, Microsoft.AspNet.Mvc.ModelBinding.IValueProvider, System.Collections.Generic.IList<Microsoft.AspNet.Mvc.IInputFormatter>, Microsoft.AspNet.Mvc.ModelBinding.Validation.IObjectModelValidator, Microsoft.AspNet.Mvc.ModelBinding.Validation.IModelValidatorProvider)

Updates the specified <paramref name=”model” /> instance using the specified <paramref name=”modelBinder” /> and the specified <paramref name=”valueProvider” /> and executes validation using the specified

<paramref name=”validatorProvider” />.

Arguments:
Return type:

System.Threading.Tasks.Task{System.Boolean}

Returns:

A [System.Threading.Tasks.Task]() that on completion returns <c>true</c> if the update is successful

public static Task<bool> TryUpdateModelAsync<TModel>(TModel model, string prefix, HttpContext httpContext, ModelStateDictionary modelState, IModelMetadataProvider metadataProvider, IModelBinder modelBinder, IValueProvider valueProvider, IList<IInputFormatter> inputFormatters, IObjectModelValidator objectModelValidator, IModelValidatorProvider validatorProvider)where TModel : class
Microsoft.AspNet.Mvc.ModelBindingHelper.TryUpdateModelAsync<TModel>(TModel, System.String, HttpContext, Microsoft.AspNet.Mvc.ModelBinding.ModelStateDictionary, Microsoft.AspNet.Mvc.ModelBinding.IModelMetadataProvider, Microsoft.AspNet.Mvc.ModelBinding.IModelBinder, Microsoft.AspNet.Mvc.ModelBinding.IValueProvider, System.Collections.Generic.IList<Microsoft.AspNet.Mvc.IInputFormatter>, Microsoft.AspNet.Mvc.ModelBinding.Validation.IObjectModelValidator, Microsoft.AspNet.Mvc.ModelBinding.Validation.IModelValidatorProvider, System.Func<Microsoft.AspNet.Mvc.ModelBinding.ModelBindingContext, System.String, System.Boolean>)

Updates the specified <paramref name=”model” /> instance using the specified <paramref name=”modelBinder” /> and the specified <paramref name=”valueProvider” /> and executes validation using the specified

<paramref name=”validatorProvider” />.

Arguments:
  • model (TModel) – The model instance to update and validate.
  • prefix (System.String) – The prefix to use when looking up values in the <paramref name=”valueProvider” />.
  • httpContext (HttpContext) – The @!:HttpContext- for the current executing request.
  • modelState (Microsoft.AspNet.Mvc.ModelBinding.ModelStateDictionary) – The [Microsoft.AspNet.Mvc.ModelBinding.ModelStateDictionary]() used for maintaining state and results of model-binding validation.
  • metadataProvider (Microsoft.AspNet.Mvc.ModelBinding.IModelMetadataProvider) – The provider used for reading metadata for the model type.
  • modelBinder (Microsoft.AspNet.Mvc.ModelBinding.IModelBinder) – The [Microsoft.AspNet.Mvc.ModelBinding.IModelBinder]() used for binding.
  • valueProvider (Microsoft.AspNet.Mvc.ModelBinding.IValueProvider) – The [Microsoft.AspNet.Mvc.ModelBinding.IValueProvider]() used for looking up values.
  • inputFormatters (System.Collections.Generic.IList{Microsoft.AspNet.Mvc.IInputFormatter}) – The set of [Microsoft.AspNet.Mvc.IInputFormatter]() instances for deserializing the body.
  • objectModelValidator (Microsoft.AspNet.Mvc.ModelBinding.Validation.IObjectModelValidator) – The [Microsoft.AspNet.Mvc.ModelBinding.Validation.IObjectModelValidator](Microsoft.AspNet.Mvc.ModelBinding.Validation.IObjectModelValidator.yml) used for validating the bound values.
  • validatorProvider (Microsoft.AspNet.Mvc.ModelBinding.Validation.IModelValidatorProvider) – The [Microsoft.AspNet.Mvc.ModelBinding.Validation.IModelValidatorProvider]() used for executing validation on the model instance.
  • predicate (System.Func{Microsoft.AspNet.Mvc.ModelBinding.ModelBindingContext,System.String,System.Boolean}) – A predicate which can be used to filter properties(for inclusion/exclusion) at runtime.
Return type:

System.Threading.Tasks.Task{System.Boolean}

Returns:

A [System.Threading.Tasks.Task]() that on completion returns <c>true</c> if the update is successful

public static Task<bool> TryUpdateModelAsync<TModel>(TModel model, string prefix, HttpContext httpContext, ModelStateDictionary modelState, IModelMetadataProvider metadataProvider, IModelBinder modelBinder, IValueProvider valueProvider, IList<IInputFormatter> inputFormatters, IObjectModelValidator objectModelValidator, IModelValidatorProvider validatorProvider, Func<ModelBindingContext, string, bool> predicate)where TModel : class
Microsoft.AspNet.Mvc.ModelBindingHelper.TryUpdateModelAsync<TModel>(TModel, System.String, HttpContext, Microsoft.AspNet.Mvc.ModelBinding.ModelStateDictionary, Microsoft.AspNet.Mvc.ModelBinding.IModelMetadataProvider, Microsoft.AspNet.Mvc.ModelBinding.IModelBinder, Microsoft.AspNet.Mvc.ModelBinding.IValueProvider, System.Collections.Generic.IList<Microsoft.AspNet.Mvc.IInputFormatter>, Microsoft.AspNet.Mvc.ModelBinding.Validation.IObjectModelValidator, Microsoft.AspNet.Mvc.ModelBinding.Validation.IModelValidatorProvider, System.Linq.Expressions.Expression<System.Func<TModel, System.Object>>[])

Updates the specified <paramref name=”model” /> instance using the specified <paramref name=”modelBinder” /> and the specified <paramref name=”valueProvider” /> and executes validation using the specified

<paramref name=”validatorProvider” />.

Arguments:
  • model (TModel) – The model instance to update and validate.
  • prefix (System.String) – The prefix to use when looking up values in the <paramref name=”valueProvider” />.
  • httpContext (HttpContext) – The @!:HttpContext- for the current executing request.
  • modelState (Microsoft.AspNet.Mvc.ModelBinding.ModelStateDictionary) – The [Microsoft.AspNet.Mvc.ModelBinding.ModelStateDictionary]() used for maintaining state and results of model-binding validation.
  • metadataProvider (Microsoft.AspNet.Mvc.ModelBinding.IModelMetadataProvider) – The provider used for reading metadata for the model type.
  • modelBinder (Microsoft.AspNet.Mvc.ModelBinding.IModelBinder) – The [Microsoft.AspNet.Mvc.ModelBinding.IModelBinder]() used for binding.
  • valueProvider (Microsoft.AspNet.Mvc.ModelBinding.IValueProvider) – The [Microsoft.AspNet.Mvc.ModelBinding.IValueProvider]() used for looking up values.
  • inputFormatters (System.Collections.Generic.IList{Microsoft.AspNet.Mvc.IInputFormatter}) – The set of [Microsoft.AspNet.Mvc.IInputFormatter]() instances for deserializing the body.
  • objectModelValidator (Microsoft.AspNet.Mvc.ModelBinding.Validation.IObjectModelValidator) – The [Microsoft.AspNet.Mvc.ModelBinding.Validation.IObjectModelValidator](Microsoft.AspNet.Mvc.ModelBinding.Validation.IObjectModelValidator.yml) used for validating the bound values.
  • validatorProvider (Microsoft.AspNet.Mvc.ModelBinding.Validation.IModelValidatorProvider) – The [Microsoft.AspNet.Mvc.ModelBinding.Validation.IModelValidatorProvider]() used for executing validation on the model instance.
  • includeExpressions (System.Linq.Expressions.Expression{System.Func{{TModel},System.Object}}[]) – Expression(s) which represent top level properties which need to be included for the current model.
Return type:

System.Threading.Tasks.Task{System.Boolean}

Returns:

A [System.Threading.Tasks.Task]() that on completion returns <c>true</c> if the update is successful

public static Task<bool> TryUpdateModelAsync<TModel>(TModel model, string prefix, HttpContext httpContext, ModelStateDictionary modelState, IModelMetadataProvider metadataProvider, IModelBinder modelBinder, IValueProvider valueProvider, IList<IInputFormatter> inputFormatters, IObjectModelValidator objectModelValidator, IModelValidatorProvider validatorProvider, params Expression<Func<TModel, object>>[] includeExpressions)where TModel : class