ModelStateDictionary ModelStateDictionary ModelStateDictionary ModelStateDictionary Class

Definition

Represents the state of an attempt to bind values from an HTTP Request to an action method, which includes validation information.

public ref class ModelStateDictionary : System::Collections::Generic::IEnumerable<System::Collections::Generic::KeyValuePair<System::String ^, Microsoft::AspNetCore::Mvc::ModelBinding::ModelStateEntry ^>>, System::Collections::Generic::IReadOnlyCollection<System::Collections::Generic::KeyValuePair<System::String ^, Microsoft::AspNetCore::Mvc::ModelBinding::ModelStateEntry ^>>, System::Collections::Generic::IReadOnlyDictionary<System::String ^, Microsoft::AspNetCore::Mvc::ModelBinding::ModelStateEntry ^>
public class ModelStateDictionary : System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string,Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateEntry>>, System.Collections.Generic.IReadOnlyCollection<System.Collections.Generic.KeyValuePair<string,Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateEntry>>, System.Collections.Generic.IReadOnlyDictionary<string,Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateEntry>
type ModelStateDictionary = class
    interface seq<KeyValuePair<string, ModelStateEntry>>
    interface IEnumerable
    interface IReadOnlyCollection<KeyValuePair<string, ModelStateEntry>>
    interface IReadOnlyDictionary<string, ModelStateEntry>
Public Class ModelStateDictionary
Implements IEnumerable(Of KeyValuePair(Of String, ModelStateEntry)), IReadOnlyCollection(Of KeyValuePair(Of String, ModelStateEntry)), IReadOnlyDictionary(Of String, ModelStateEntry)
Inheritance
ModelStateDictionaryModelStateDictionaryModelStateDictionaryModelStateDictionary
Implements

Constructors

ModelStateDictionary() ModelStateDictionary() ModelStateDictionary() ModelStateDictionary()

Initializes a new instance of the ModelStateDictionary class.

ModelStateDictionary(ModelStateDictionary) ModelStateDictionary(ModelStateDictionary) ModelStateDictionary(ModelStateDictionary) ModelStateDictionary(ModelStateDictionary)

Initializes a new instance of the ModelStateDictionary class by using values that are copied from the specified dictionary.

ModelStateDictionary(Int32) ModelStateDictionary(Int32) ModelStateDictionary(Int32) ModelStateDictionary(Int32)

Initializes a new instance of the ModelStateDictionary class.

Fields

DefaultMaxAllowedErrors DefaultMaxAllowedErrors DefaultMaxAllowedErrors DefaultMaxAllowedErrors

The default value for MaxAllowedErrors of 200.

Properties

Count Count Count Count
ErrorCount ErrorCount ErrorCount ErrorCount

Gets the number of errors added to this instance of ModelStateDictionary via AddModelError or TryAddModelError.

HasReachedMaxErrors HasReachedMaxErrors HasReachedMaxErrors HasReachedMaxErrors

Gets a value indicating whether or not the maximum number of errors have been recorded.

IsValid IsValid IsValid IsValid

Gets a value that indicates whether any model state values in this model state dictionary is invalid or not validated.

Item[String] Item[String] Item[String] Item[String]
Keys Keys Keys Keys

Gets the key sequence.

MaxAllowedErrors MaxAllowedErrors MaxAllowedErrors MaxAllowedErrors

Gets or sets the maximum allowed model state errors in this instance of ModelStateDictionary. Defaults to 200.

Root Root Root Root

Root entry for the ModelStateDictionary.

ValidationState ValidationState ValidationState ValidationState
Values Values Values Values

Gets the value sequence.

Methods

AddModelError(String, String) AddModelError(String, String) AddModelError(String, String) AddModelError(String, String)

Adds the specified errorMessage to the Errors instance that is associated with the specified key. If the maximum number of allowed errors has already been recorded, ensures that a TooManyModelErrorsException exception is recorded instead.

AddModelError(String, Exception, ModelMetadata) AddModelError(String, Exception, ModelMetadata) AddModelError(String, Exception, ModelMetadata) AddModelError(String, Exception, ModelMetadata)

Adds the specified exception to the Errors instance that is associated with the specified key. If the maximum number of allowed errors has already been recorded, ensures that a TooManyModelErrorsException exception is recorded instead.

Clear() Clear() Clear() Clear()

Removes all keys and values from this instance of ModelStateDictionary.

ClearValidationState(String) ClearValidationState(String) ClearValidationState(String) ClearValidationState(String)

Clears ModelStateDictionary entries that match the key that is passed as parameter.

ContainsKey(String) ContainsKey(String) ContainsKey(String) ContainsKey(String)
FindKeysWithPrefix(String) FindKeysWithPrefix(String) FindKeysWithPrefix(String) FindKeysWithPrefix(String)

Gets a ModelStateDictionary.PrefixEnumerable that iterates over this instance of ModelStateDictionary using the specified prefix.

GetEnumerator() GetEnumerator() GetEnumerator() GetEnumerator()

Returns an enumerator that iterates through this instance of ModelStateDictionary.

GetFieldValidationState(String) GetFieldValidationState(String) GetFieldValidationState(String) GetFieldValidationState(String)

Returns the aggregate ModelValidationState for items starting with the specified key.

GetValidationState(String) GetValidationState(String) GetValidationState(String) GetValidationState(String)

Returns ModelValidationState for the key.

MarkFieldSkipped(String) MarkFieldSkipped(String) MarkFieldSkipped(String) MarkFieldSkipped(String)

Marks the ValidationState for the entry with the specified key as Skipped.

MarkFieldValid(String) MarkFieldValid(String) MarkFieldValid(String) MarkFieldValid(String)

Marks the ValidationState for the entry with the specified key as Valid.

Merge(ModelStateDictionary) Merge(ModelStateDictionary) Merge(ModelStateDictionary) Merge(ModelStateDictionary)

Copies the values from the specified dictionary into this instance, overwriting existing values if keys are the same.

Remove(String) Remove(String) Remove(String) Remove(String)

Removes the ModelStateEntry with the specified key.

SetModelValue(String, ValueProviderResult) SetModelValue(String, ValueProviderResult) SetModelValue(String, ValueProviderResult) SetModelValue(String, ValueProviderResult)

Sets the value for the ModelStateEntry with the specified key.

SetModelValue(String, Object, String) SetModelValue(String, Object, String) SetModelValue(String, Object, String) SetModelValue(String, Object, String)

Sets the of RawValue and AttemptedValue for the ModelStateEntry with the specified key.

StartsWithPrefix(String, String) StartsWithPrefix(String, String) StartsWithPrefix(String, String) StartsWithPrefix(String, String)

This API supports the MVC's infrastructure and is not intended to be used directly from your code. This API may change or be removed in future releases.

TryAddModelError(String, Exception, ModelMetadata) TryAddModelError(String, Exception, ModelMetadata) TryAddModelError(String, Exception, ModelMetadata) TryAddModelError(String, Exception, ModelMetadata)

Attempts to add the specified exception to the Errors instance that is associated with the specified key. If the maximum number of allowed errors has already been recorded, ensures that a TooManyModelErrorsException exception is recorded instead.

TryAddModelError(String, String) TryAddModelError(String, String) TryAddModelError(String, String) TryAddModelError(String, String)

Attempts to add the specified errorMessage to the Errors instance that is associated with the specified key. If the maximum number of allowed errors has already been recorded, ensures that a TooManyModelErrorsException exception is recorded instead.

TryAddModelException(String, Exception) TryAddModelException(String, Exception) TryAddModelException(String, Exception) TryAddModelException(String, Exception)

Adds the specified exception to the Errors instance that is associated with the specified key. If the maximum number of allowed errors has already been recorded, ensures that a TooManyModelErrorsException exception is recorded instead.

TryGetValue(String, ModelStateEntry) TryGetValue(String, ModelStateEntry) TryGetValue(String, ModelStateEntry) TryGetValue(String, ModelStateEntry)

Explicit Interface Implementations

IEnumerable<KeyValuePair<String,ModelStateEntry>>.GetEnumerator() IEnumerable<KeyValuePair<String,ModelStateEntry>>.GetEnumerator() IEnumerable<KeyValuePair<String,ModelStateEntry>>.GetEnumerator() IEnumerable<KeyValuePair<String,ModelStateEntry>>.GetEnumerator()
IReadOnlyDictionary<String,ModelStateEntry>.Keys IReadOnlyDictionary<String,ModelStateEntry>.Keys IReadOnlyDictionary<String,ModelStateEntry>.Keys IReadOnlyDictionary<String,ModelStateEntry>.Keys
IReadOnlyDictionary<String,ModelStateEntry>.Values IReadOnlyDictionary<String,ModelStateEntry>.Values IReadOnlyDictionary<String,ModelStateEntry>.Values IReadOnlyDictionary<String,ModelStateEntry>.Values
IEnumerable.GetEnumerator() IEnumerable.GetEnumerator() IEnumerable.GetEnumerator() IEnumerable.GetEnumerator()

Extension Methods

AddModelError<TModel>(ModelStateDictionary, Expression<Func<TModel,Object>>, Exception, ModelMetadata) AddModelError<TModel>(ModelStateDictionary, Expression<Func<TModel,Object>>, Exception, ModelMetadata) AddModelError<TModel>(ModelStateDictionary, Expression<Func<TModel,Object>>, Exception, ModelMetadata) AddModelError<TModel>(ModelStateDictionary, Expression<Func<TModel,Object>>, Exception, ModelMetadata)

Adds the specified exception to the Errors instance that is associated with the specified expression. If the maximum number of allowed errors has already been recorded, ensures that a TooManyModelErrorsException exception is recorded instead.

AddModelError<TModel>(ModelStateDictionary, Expression<Func<TModel,Object>>, String) AddModelError<TModel>(ModelStateDictionary, Expression<Func<TModel,Object>>, String) AddModelError<TModel>(ModelStateDictionary, Expression<Func<TModel,Object>>, String) AddModelError<TModel>(ModelStateDictionary, Expression<Func<TModel,Object>>, String)

Adds the specified errorMessage to the Errors instance that is associated with the specified expression. If the maximum number of allowed errors has already been recorded, ensures that a TooManyModelErrorsException exception is recorded instead.

Remove<TModel>(ModelStateDictionary, Expression<Func<TModel,Object>>) Remove<TModel>(ModelStateDictionary, Expression<Func<TModel,Object>>) Remove<TModel>(ModelStateDictionary, Expression<Func<TModel,Object>>) Remove<TModel>(ModelStateDictionary, Expression<Func<TModel,Object>>)

Removes the specified expression from the ModelStateDictionary.

RemoveAll<TModel>(ModelStateDictionary, Expression<Func<TModel,Object>>) RemoveAll<TModel>(ModelStateDictionary, Expression<Func<TModel,Object>>) RemoveAll<TModel>(ModelStateDictionary, Expression<Func<TModel,Object>>) RemoveAll<TModel>(ModelStateDictionary, Expression<Func<TModel,Object>>)

Removes all the entries for the specified expression from the ModelStateDictionary.

TryAddModelException<TModel>(ModelStateDictionary, Expression<Func<TModel,Object>>, Exception) TryAddModelException<TModel>(ModelStateDictionary, Expression<Func<TModel,Object>>, Exception) TryAddModelException<TModel>(ModelStateDictionary, Expression<Func<TModel,Object>>, Exception) TryAddModelException<TModel>(ModelStateDictionary, Expression<Func<TModel,Object>>, Exception)

Adds the specified exception to the Errors instance that is associated with the specified expression. If the maximum number of allowed errors has already been recorded, ensures that a TooManyModelErrorsException exception is recorded instead.

Applies to