Freigeben über


ModelStateDictionary Class

Represents the state of an attempt to bind a posted form to an action method, which includes validation information.

Inheritance Hierarchy

System.Object
  System.Web.Mvc.ModelStateDictionary

Namespace:  System.Web.Mvc
Assembly:  System.Web.Mvc (in System.Web.Mvc.dll)

Syntax

'Declaration
<SerializableAttribute> _
Public Class ModelStateDictionary _
    Implements IDictionary(Of String, ModelState),  _
    ICollection(Of KeyValuePair(Of String, ModelState)), IEnumerable(Of KeyValuePair(Of String, ModelState)),  _
    IEnumerable
[SerializableAttribute]
public class ModelStateDictionary : IDictionary<string, ModelState>, 
    ICollection<KeyValuePair<string, ModelState>>, IEnumerable<KeyValuePair<string, ModelState>>, 
    IEnumerable
[SerializableAttribute]
public ref class ModelStateDictionary : IDictionary<String^, ModelState^>, 
    ICollection<KeyValuePair<String^, ModelState^>>, IEnumerable<KeyValuePair<String^, ModelState^>>, 
    IEnumerable

The ModelStateDictionary type exposes the following members.

Constructors

  Name Description
Public method ModelStateDictionary() Initializes a new instance of the ModelStateDictionary class.
Public method ModelStateDictionary(ModelStateDictionary) Initializes a new instance of the ModelStateDictionary class by using values that are copied from the specified model-state dictionary.

Top

Properties

  Name Description
Public property Count Gets the number of key/value pairs in the collection.
Public property IsReadOnly Gets a value that indicates whether the collection is read-only.
Public property IsValid Gets a value that indicates whether this instance of the model-state dictionary is valid.
Public property Item Gets or sets the value that is associated with the specified key.
Public property Keys Gets a collection that contains the keys in the dictionary.
Public property Values Gets a collection that contains the values in the dictionary.

Top

Methods

  Name Description
Public method Add(KeyValuePair<String, ModelState>) Adds the specified item to the model-state dictionary.
Public method Add(String, ModelState) Adds an element that has the specified key and value to the model-state dictionary.
Public method AddModelError(String, Exception) Adds the specified model error to the errors collection for the model-state dictionary that is associated with the specified key.
Public method AddModelError(String, String) Adds the specified error message to the errors collection for the model-state dictionary that is associated with the specified key.
Public method Clear Removes all items from the model-state dictionary.
Public method Contains Determines whether the model-state dictionary contains a specific value.
Public method ContainsKey Determines whether the model-state dictionary contains the specified key.
Public method CopyTo Copies the elements of the model-state dictionary to an array, starting at a specified index.
Public method Equals Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetEnumerator Returns an enumerator that can be used to iterate through the collection.
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Public method IsValidField Determines whether there are any ModelError objects that are associated with or prefixed with the specified key.
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method Merge Copies the values from the specified ModelStateDictionary object into this dictionary, overwriting existing values if keys are the same.
Public method Remove(KeyValuePair<String, ModelState>) Removes the first occurrence of the specified object from the model-state dictionary.
Public method Remove(String) Removes the element that has the specified key from the model-state dictionary.
Public method SetModelValue Sets the value for the specified key by using the specified value provider dictionary.
Public method ToString Returns a string that represents the current object. (Inherited from Object.)
Public method TryGetValue Attempts to gets the value that is associated with the specified key.

Top

Explicit Interface Implementations

  Name Description
Explicit interface implemetationPrivate method IEnumerable.GetEnumerator Returns an enumerator that can be used to iterate through the collection.

Top

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

System.Web.Mvc Namespace