ModelBindingHelper Class

Namespace
Microsoft.AspNetCore.Mvc.ModelBinding.Internal
Assemblies
  • Microsoft.AspNetCore.Mvc.Core

Syntax

public class ModelBindingHelper
class Microsoft.AspNetCore.Mvc.ModelBinding.Internal.ModelBindingHelper

Methods

CanGetCompatibleCollection<T>(Microsoft.AspNetCore.Mvc.ModelBinding.ModelBindingContext)

Gets an indication whether GetCompatibleCollection{T} is likely to return a usable non-<code>null</code> value.

Arguments:bindingContext (Microsoft.AspNetCore.Mvc.ModelBinding.ModelBindingContext) – The Microsoft.AspNetCore.Mvc.ModelBinding.ModelBindingContext.
Return type:System.Boolean
Returns:<code>true</code> if GetCompatibleCollection{T} is likely to return a usable non-<code>null</code> value; <code>false</code> otherwise.
public static bool CanGetCompatibleCollection<T>(ModelBindingContext bindingContext)
ClearValidationStateForModel(Microsoft.AspNetCore.Mvc.ModelBinding.ModelMetadata, Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary, System.String)

Clears Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary entries for Microsoft.AspNetCore.Mvc.ModelBinding.ModelMetadata.

Arguments:
public static void ClearValidationStateForModel(ModelMetadata modelMetadata, ModelStateDictionary modelState, string modelKey)
ClearValidationStateForModel(System.Type, Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary, Microsoft.AspNetCore.Mvc.ModelBinding.IModelMetadataProvider, System.String)

Clears Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary entries for Microsoft.AspNetCore.Mvc.ModelBinding.ModelMetadata.

Arguments:
public static void ClearValidationStateForModel(Type modelType, ModelStateDictionary modelState, IModelMetadataProvider metadataProvider, string modelKey)
ConvertTo(System.Object, System.Type)

Converts the provided <em>value</em> to a value of System.Type <em>type</em> using the System.Globalization.CultureInfo.InvariantCulture.

Arguments:
  • value (System.Object) – The value to convert.
  • type (System.Type) – The System.Type for conversion.
Return type:

System.Object

Returns:

The converted value or <code>null</code> if the value could not be converted.

public static object ConvertTo(object value, Type type)
ConvertTo(System.Object, System.Type, System.Globalization.CultureInfo)

Converts the provided <em>value</em> to a value of System.Type <em>type</em>.

Arguments:
  • value (System.Object) – The value to convert.”/>
  • type (System.Type) – The System.Type for conversion.
  • culture (System.Globalization.CultureInfo) – The System.Globalization.CultureInfo for conversion.
Return type:

System.Object

Returns:

The converted value or <code>null</code> if the value could not be converted.

public static object ConvertTo(object value, Type type, CultureInfo culture)
ConvertTo<T>(System.Object)

Converts the provided <em>value</em> to a value of System.Type <em>T</em> using the System.Globalization.CultureInfo.InvariantCulture.

Arguments:value (System.Object) – The value to convert.”/>
Return type:T
Returns:The converted value or the default value of <em>T</em> if the value could not be converted.
public static T ConvertTo<T>(object value)
ConvertTo<T>(System.Object, System.Globalization.CultureInfo)

Converts the provided <em>value</em> to a value of System.Type <em>T</em>.

Arguments:
  • value (System.Object) – The value to convert.”/>
  • culture (System.Globalization.CultureInfo) – The System.Globalization.CultureInfo for conversion.
Return type:

T

Returns:

The converted value or the default value of <em>T</em> if the value could not be converted.

public static T ConvertTo<T>(object value, CultureInfo culture)
GetCompatibleCollection<T>(Microsoft.AspNetCore.Mvc.ModelBinding.ModelBindingContext)

Creates an System.Collections.Generic.ICollection`1 instance compatible with <em>bindingContext</em>’s Microsoft.AspNetCore.Mvc.ModelBinding.ModelBindingContext.ModelType.

Arguments:bindingContext (Microsoft.AspNetCore.Mvc.ModelBinding.ModelBindingContext) – The Microsoft.AspNetCore.Mvc.ModelBinding.ModelBindingContext.
Return type:System.Collections.Generic.ICollection<T>
Returns:An System.Collections.Generic.ICollection`1 instance compatible with <em>bindingContext</em>’s Microsoft.AspNetCore.Mvc.ModelBinding.ModelBindingContext.ModelType.
public static ICollection<T> GetCompatibleCollection<T>(ModelBindingContext bindingContext)
GetCompatibleCollection<T>(Microsoft.AspNetCore.Mvc.ModelBinding.ModelBindingContext, System.Int32)

Creates an System.Collections.Generic.ICollection`1 instance compatible with <em>bindingContext</em>’s Microsoft.AspNetCore.Mvc.ModelBinding.ModelBindingContext.ModelType.

Arguments:
Return type:

System.Collections.Generic.ICollection<T>

Returns:

An System.Collections.Generic.ICollection`1 instance compatible with <em>bindingContext</em>’s Microsoft.AspNetCore.Mvc.ModelBinding.ModelBindingContext.ModelType.

public static ICollection<T> GetCompatibleCollection<T>(ModelBindingContext bindingContext, int capacity)
GetPropertyFilterExpression<TModel>(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:expressions (System.Linq.Expressions.Expression<System.Linq.Expressions.Expression`1>{System.Func<System.Func`2>{TModel, System.Object<System.Object>}}[]) – Expressions identifying the properties to allow for binding.
Return type:System.Linq.Expressions.Expression<System.Func<Microsoft.AspNetCore.Mvc.ModelBinding.ModelMetadata>>
Returns:An expression which can be used with Microsoft.AspNetCore.Mvc.ModelBinding.IPropertyFilterProvider.
public static Expression<Func<ModelMetadata, bool>> GetPropertyFilterExpression<TModel>(Expression<Func<TModel, object>>[] expressions)
TryUpdateModelAsync(System.Object, System.Type, System.String, Microsoft.AspNetCore.Mvc.ActionContext, Microsoft.AspNetCore.Mvc.ModelBinding.IModelMetadataProvider, Microsoft.AspNetCore.Mvc.ModelBinding.IModelBinderFactory, Microsoft.AspNetCore.Mvc.ModelBinding.IValueProvider, Microsoft.AspNetCore.Mvc.ModelBinding.Validation.IObjectModelValidator)

Updates the specified <em>model</em> instance using the specified <em>modelBinderFactory</em> and the specified <em>valueProvider</em> and executes validation using the specified <em>objectModelValidator</em>.

Arguments:
Return type:

System.Threading.Tasks.Task<System.Boolean>

Returns:

A System.Threading.Tasks.Task that on completion returns <code>true</code> if the update is successful

public static Task<bool> TryUpdateModelAsync(object model, Type modelType, string prefix, ActionContext actionContext, IModelMetadataProvider metadataProvider, IModelBinderFactory modelBinderFactory, IValueProvider valueProvider, IObjectModelValidator objectModelValidator)
TryUpdateModelAsync(System.Object, System.Type, System.String, Microsoft.AspNetCore.Mvc.ActionContext, Microsoft.AspNetCore.Mvc.ModelBinding.IModelMetadataProvider, Microsoft.AspNetCore.Mvc.ModelBinding.IModelBinderFactory, Microsoft.AspNetCore.Mvc.ModelBinding.IValueProvider, Microsoft.AspNetCore.Mvc.ModelBinding.Validation.IObjectModelValidator, System.Func<Microsoft.AspNetCore.Mvc.ModelBinding.ModelMetadata, System.Boolean>)

Updates the specified <em>model</em> instance using the specified <em>modelBinderFactory</em> and the specified <em>valueProvider</em> and executes validation using the specified <em>objectModelValidator</em>.

Arguments:
Return type:

System.Threading.Tasks.Task<System.Boolean>

Returns:

A System.Threading.Tasks.Task that on completion returns <code>true</code> if the update is successful

public static Task<bool> TryUpdateModelAsync(object model, Type modelType, string prefix, ActionContext actionContext, IModelMetadataProvider metadataProvider, IModelBinderFactory modelBinderFactory, IValueProvider valueProvider, IObjectModelValidator objectModelValidator, Func<ModelMetadata, bool> propertyFilter)
TryUpdateModelAsync<TModel>(TModel, System.String, Microsoft.AspNetCore.Mvc.ActionContext, Microsoft.AspNetCore.Mvc.ModelBinding.IModelMetadataProvider, Microsoft.AspNetCore.Mvc.ModelBinding.IModelBinderFactory, Microsoft.AspNetCore.Mvc.ModelBinding.IValueProvider, Microsoft.AspNetCore.Mvc.ModelBinding.Validation.IObjectModelValidator)

Updates the specified <em>model</em> instance using the specified <em>modelBinderFactory</em> and the specified <em>valueProvider</em> and executes validation using the specified <em>objectModelValidator</em>.

Arguments:
Return type:

System.Threading.Tasks.Task<System.Boolean>

Returns:

A System.Threading.Tasks.Task that on completion returns <code>true</code> if the update is successful

public static Task<bool> TryUpdateModelAsync<TModel>(TModel model, string prefix, ActionContext actionContext, IModelMetadataProvider metadataProvider, IModelBinderFactory modelBinderFactory, IValueProvider valueProvider, IObjectModelValidator objectModelValidator)where TModel : class
TryUpdateModelAsync<TModel>(TModel, System.String, Microsoft.AspNetCore.Mvc.ActionContext, Microsoft.AspNetCore.Mvc.ModelBinding.IModelMetadataProvider, Microsoft.AspNetCore.Mvc.ModelBinding.IModelBinderFactory, Microsoft.AspNetCore.Mvc.ModelBinding.IValueProvider, Microsoft.AspNetCore.Mvc.ModelBinding.Validation.IObjectModelValidator, System.Func<Microsoft.AspNetCore.Mvc.ModelBinding.ModelMetadata, System.Boolean>)

Updates the specified <em>model</em> instance using the specified <em>modelBinderFactory</em> and the specified <em>valueProvider</em> and executes validation using the specified <em>objectModelValidator</em>.

Arguments:
Return type:

System.Threading.Tasks.Task<System.Boolean>

Returns:

A System.Threading.Tasks.Task that on completion returns <code>true</code> if the update is successful

public static Task<bool> TryUpdateModelAsync<TModel>(TModel model, string prefix, ActionContext actionContext, IModelMetadataProvider metadataProvider, IModelBinderFactory modelBinderFactory, IValueProvider valueProvider, IObjectModelValidator objectModelValidator, Func<ModelMetadata, bool> propertyFilter)where TModel : class
TryUpdateModelAsync<TModel>(TModel, System.String, Microsoft.AspNetCore.Mvc.ActionContext, Microsoft.AspNetCore.Mvc.ModelBinding.IModelMetadataProvider, Microsoft.AspNetCore.Mvc.ModelBinding.IModelBinderFactory, Microsoft.AspNetCore.Mvc.ModelBinding.IValueProvider, Microsoft.AspNetCore.Mvc.ModelBinding.Validation.IObjectModelValidator, System.Linq.Expressions.Expression<System.Func<TModel, System.Object>>[])

Updates the specified <em>model</em> instance using the specified <em>modelBinderFactory</em> and the specified <em>valueProvider</em> and executes validation using the specified <em>objectModelValidator</em>.

Arguments:
Return type:

System.Threading.Tasks.Task<System.Boolean>

Returns:

A System.Threading.Tasks.Task that on completion returns <code>true</code> if the update is successful

public static Task<bool> TryUpdateModelAsync<TModel>(TModel model, string prefix, ActionContext actionContext, IModelMetadataProvider metadataProvider, IModelBinderFactory modelBinderFactory, IValueProvider valueProvider, IObjectModelValidator objectModelValidator, params Expression<Func<TModel, object>>[] includeExpressions)where TModel : class