Share via


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 IReadOnlyDictionary<string, ModelStateEntry>
    interface seq<KeyValuePair<string, ModelStateEntry>>
    interface IEnumerable
    interface IReadOnlyCollection<KeyValuePair<string, 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
ModelStateDictionary
Implements

Constructors

ModelStateDictionary()

Initializes a new instance of the ModelStateDictionary class.

ModelStateDictionary(Int32)

Initializes a new instance of the ModelStateDictionary class.

ModelStateDictionary(ModelStateDictionary)

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

Fields

DefaultMaxAllowedErrors

The default value for MaxAllowedErrors of 200.

Properties

Count

Gets the number of elements in the collection.

ErrorCount

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

HasReachedMaxErrors

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

IsValid

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

Item[String]

Gets the element that has the specified key in the read-only dictionary.

Keys

Gets the key sequence.

MaxAllowedErrors

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

Root

Root entry for the ModelStateDictionary.

ValidationState System.Object.ValidationState
Values

Gets the value sequence.

Methods

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.

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.

Clear()

Removes all keys and values from this instance of ModelStateDictionary.

ClearValidationState(String)

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

ContainsKey(String)

Determines whether the read-only dictionary contains an element that has the specified key.

FindKeysWithPrefix(String)

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

GetEnumerator()

Returns an enumerator that iterates through this instance of ModelStateDictionary.

GetFieldValidationState(String)

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

GetValidationState(String)

Returns ModelValidationState for the key.

MarkFieldSkipped(String)

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

MarkFieldValid(String)

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

Merge(ModelStateDictionary)

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

Remove(String)

Removes the ModelStateEntry with the specified key.

SetModelValue(String, Object, String)

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

SetModelValue(String, ValueProviderResult)

Sets the value for the ModelStateEntry with the specified key.

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)

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)

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)

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) System.Object.TryGetValue(System.String,Microsoft.AspNetCore.Mvc.ModelBinding.ModelStateEntry@)

Explicit Interface Implementations

IEnumerable.GetEnumerator()

Returns an enumerator that iterates through a collection.

IEnumerable<KeyValuePair<String,ModelStateEntry>>.GetEnumerator()

Returns an enumerator that iterates through the collection.

IReadOnlyDictionary<String,ModelStateEntry>.Keys

Gets an enumerable collection that contains the keys in the read-only dictionary.

IReadOnlyDictionary<String,ModelStateEntry>.Values

Gets an enumerable collection that contains the values in the read-only dictionary.

Extension Methods

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)

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>>)

Removes the specified expression from the ModelStateDictionary.

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)

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