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: - modelState (Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary) – The
Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary
instance this method extends. - expression (System.Linq.Expressions.Expression<System.Func<TModel, System.Object>>) – An expression to be evaluated against an item in the current model.
- exception (System.Exception) – The
System.Exception
to add. - metadata (Microsoft.AspNetCore.Mvc.ModelBinding.ModelMetadata) – The
Microsoft.AspNetCore.Mvc.ModelBinding.ModelMetadata
associated with the model.
public static void AddModelError<TModel>(this ModelStateDictionary modelState, Expression<Func<TModel, object>> expression, Exception exception, ModelMetadata metadata)
- modelState (Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary) – The
-
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: - modelState (Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary) – The
Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary
instance this method extends. - expression (System.Linq.Expressions.Expression<System.Func<TModel, System.Object>>) – An expression to be evaluated against an item in the current model.
- errorMessage (System.String) – The error message to add.
public static void AddModelError<TModel>(this ModelStateDictionary modelState, Expression<Func<TModel, object>> expression, string errorMessage)
- modelState (Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary) – The
-
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: - modelState (Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary) – The
Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary
instance this method extends. - expression (System.Linq.Expressions.Expression<System.Func<TModel, System.Object>>) – An expression to be evaluated against an item in the current model.
public static void RemoveAll<TModel>(this ModelStateDictionary modelState, Expression<Func<TModel, object>> expression)
- modelState (Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary) – The
-
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: - modelState (Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary) – The
Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary
instance this method extends. - expression (System.Linq.Expressions.Expression<System.Func<TModel, System.Object>>) – An expression to be evaluated against an item in the current model.
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)
- modelState (Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateDictionary) – The
-