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 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>>
Public Class ModelStateDictionary
Implements IEnumerable(Of KeyValuePair(Of String, ModelStateEntry)), IReadOnlyCollection(Of KeyValuePair(Of String, ModelStateEntry)), IReadOnlyDictionary(Of String, ModelStateEntry)
Inheritance
ModelStateDictionaryModelStateDictionaryModelStateDictionary
Implements

Constructors

ModelStateDictionary() ModelStateDictionary() ModelStateDictionary()

Initializes a new instance of the ModelStateDictionary class.

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)

Initializes a new instance of the ModelStateDictionary class.

Fields

DefaultMaxAllowedErrors DefaultMaxAllowedErrors DefaultMaxAllowedErrors

The default value for MaxAllowedErrors of 200.

Properties

Count Count Count
ErrorCount ErrorCount ErrorCount

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

HasReachedMaxErrors HasReachedMaxErrors HasReachedMaxErrors

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

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]
Keys Keys Keys

Gets the key sequence.

MaxAllowedErrors MaxAllowedErrors MaxAllowedErrors

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

Root Root Root

Root entry for the ModelStateDictionary.

ValidationState ValidationState ValidationState
Values Values Values

Gets the value sequence.

Methods

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)

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

Removes all keys and values from this instance of ModelStateDictionary.

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

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

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

Returns an enumerator that iterates through this instance of ModelStateDictionary.

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

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

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

Returns ModelValidationState for the key.

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

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

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

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

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)

Removes the ModelStateEntry with the specified key.

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)

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

StartsWithPrefix(String, String) StartsWithPrefix(String, String) StartsWithPrefix(String, String)
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)

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)

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)

Explicit Interface Implementations

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>.Values IReadOnlyDictionary<String,ModelStateEntry>.Values IReadOnlyDictionary<String,ModelStateEntry>.Values
IEnumerable.GetEnumerator() IEnumerable.GetEnumerator() IEnumerable.GetEnumerator()

Extension Methods

GetWrapperProvider(IEnumerable<IWrapperProviderFactory>, WrapperProviderContext) GetWrapperProvider(IEnumerable<IWrapperProviderFactory>, WrapperProviderContext) GetWrapperProvider(IEnumerable<IWrapperProviderFactory>, WrapperProviderContext)

Gets an instance of IWrapperProvider for the supplied type.

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)

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

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

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)

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.

FirstHtmlSymbolAs(IEnumerable<ISymbol>, HtmlSymbolType) FirstHtmlSymbolAs(IEnumerable<ISymbol>, HtmlSymbolType) FirstHtmlSymbolAs(IEnumerable<ISymbol>, HtmlSymbolType)

Converts the generic IEnumerable<T> to a IEnumerable<T> and finds the first HtmlSymbol with type type.

GetContent(IEnumerable<ISymbol>, SourceLocation) GetContent(IEnumerable<ISymbol>, SourceLocation) GetContent(IEnumerable<ISymbol>, SourceLocation)

Applies to