ModelStateDictionaryExtensions Class

Extensions methods for Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary.

Namespace
Microsoft.AspNetCore.Mvc.ModelBinding
Assemblies
  • Microsoft.AspNetCore.Mvc.ViewFeatures

Syntax

public class ModelStateDictionaryExtensions
class Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionaryExtensions

Methods

AddModelError<TModel>(Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary, System.Linq.Expressions.Expression<System.Func<TModel, System.Object>>, System.Exception, Microsoft.AspNetCore.Mvc.ModelBinding.ModelMetadata)

Adds the specified <em>exception</em> to the Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateEntry.Errors instance that is associated with the specified <em>expression</em>.

Arguments:
public static void AddModelError<TModel>(this ModelStateDictionary modelState, Expression<Func<TModel, object>> expression, Exception exception, ModelMetadata metadata)
AddModelError<TModel>(Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary, System.Linq.Expressions.Expression<System.Func<TModel, System.Object>>, System.String)

Adds the specified <em>errorMessage</em> to the Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateEntry.Errors instance that is associated with the specified <em>expression</em>.

Arguments:
public static void AddModelError<TModel>(this ModelStateDictionary modelState, Expression<Func<TModel, object>> expression, string errorMessage)
RemoveAll<TModel>(Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary, System.Linq.Expressions.Expression<System.Func<TModel, System.Object>>)

Removes all the entries for the specified <em>expression</em> from the Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary.

Arguments:
public static void RemoveAll<TModel>(this ModelStateDictionary modelState, Expression<Func<TModel, object>> expression)
Remove<TModel>(Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary, System.Linq.Expressions.Expression<System.Func<TModel, System.Object>>)

Removes the specified <em>expression</em> from the Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary.

Arguments:
Return type:

System.Boolean

Returns:

true if the element is successfully removed; otherwise, false. This method also returns false if <em>expression</em> was not found in the model-state dictionary.

public static bool Remove<TModel>(this ModelStateDictionary modelState, Expression<Func<TModel, object>> expression)