Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
ViewDataDictionary Class
Collapse the table of content
Expand the table of content

ViewDataDictionary Class

 

Represents a container that is used to pass data between a controller and a view.

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


No code example is currently available or this language may not be supported.

NameDescription
System_CAPS_pubmethodViewDataDictionary()

Initializes a new instance of the ViewDataDictionary class.

System_CAPS_pubmethodViewDataDictionary(Object)

Initializes a new instance of the ViewDataDictionary class by using the specified model.

System_CAPS_pubmethodViewDataDictionary(ViewDataDictionary)

Initializes a new instance of the ViewDataDictionary class by using the specified dictionary.

NameDescription
System_CAPS_pubpropertyCount

Gets the number of elements in the collection.

System_CAPS_pubpropertyIsReadOnly

Gets a value that indicates whether the collection is read-only.

System_CAPS_pubpropertyItem(String)

Gets or sets the item that is associated with the specified key.

System_CAPS_pubpropertyKeys

Gets a collection that contains the keys of this dictionary.

System_CAPS_pubpropertyModel

Gets or sets the model that is associated with the view data.

System_CAPS_pubpropertyModelMetadata

Gets or sets information about the model.

System_CAPS_pubpropertyModelState

Gets the state of the model.

System_CAPS_pubpropertyTemplateInfo

Gets or sets an object that encapsulates information about the current template context.

System_CAPS_pubpropertyValues

Gets a collection that contains the values in this dictionary.

NameDescription
System_CAPS_pubmethodAdd(KeyValuePair<String, Object>)

Adds the specified item to the collection.

System_CAPS_pubmethodAdd(String, Object)

Adds an element to the collection using the specified key and value .

System_CAPS_pubmethodClear()

Removes all items from the collection.

System_CAPS_pubmethodContains(KeyValuePair<String, Object>)

Determines whether the collection contains the specified item.

System_CAPS_pubmethodContainsKey(String)

Determines whether the collection contains an element that has the specified key.

System_CAPS_pubmethodCopyTo(KeyValuePair<String, Object>[], Int32)

Copies the elements of the collection to an array, starting at a particular index.

System_CAPS_pubmethodEquals(Object)

(Inherited from Object.)

System_CAPS_pubmethodEval(String)

Evaluates the specified expression.

System_CAPS_pubmethodEval(String, String)

Evaluates the specified expression by using the specified format.

System_CAPS_protmethodFinalize()

(Inherited from Object.)

System_CAPS_pubmethodGetEnumerator()

Returns an enumerator that can be used to iterate through the collection.

System_CAPS_pubmethodGetHashCode()

(Inherited from Object.)

System_CAPS_pubmethodGetType()

(Inherited from Object.)

System_CAPS_pubmethodGetViewDataInfo(String)

Returns information about the view data as defined by the expression parameter.

System_CAPS_protmethodMemberwiseClone()

(Inherited from Object.)

System_CAPS_pubmethodRemove(KeyValuePair<String, Object>)

Removes the first occurrence of a specified object from the collection.

System_CAPS_pubmethodRemove(String)

Removes the element from the collection using the specified key.

System_CAPS_protmethodSetModel(Object)

Sets the data model to use for the view.

System_CAPS_pubmethodToString()

(Inherited from Object.)

System_CAPS_pubmethodTryGetValue(String, Object)

Attempts to retrieve the value that is associated with the specified key.

NameDescription
System_CAPS_pubinterfaceSystem_CAPS_privmethodIEnumerable.GetEnumerator()

Returns an enumerator that can be used to iterate through the collection.

The ViewData property of a controller exposes an instance of the ViewDataDictionary class. To pass data to a view, you first add it to the controller's ViewData property in the action method that renders the view, as shown in the following example:

No code example is currently available or this language may not be supported.

When the view is rendered, the view data is copied to the ViewData property of the view. In the view markup, you can then access the data as shown in the following example:

No code example is currently available or this language may not be supported.

Similarly, you can pass data to the controller by adding the data to the ViewData property of the view, as shown in the following example:

No code example is currently available or this language may not be supported.

When the view is posted, its view data is sent to the controller, and you can then access the data in your action method as in the following example:

No code example is currently available or this language may not be supported.

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

Return to top
Show:
© 2015 Microsoft