ViewDataDictionary<TModel> Class
Represents a container that is used to pass strongly typed data between a controller and a view.
Assembly: System.Web.Mvc (in System.Web.Mvc.dll)
| Name | Description | |
|---|---|---|
![]() | ViewDataDictionary<TModel>() | Initializes a new instance of the ViewDataDictionary<TModel> class. |
![]() | ViewDataDictionary<TModel>(TModel) | Initializes a new instance of the ViewDataDictionary<TModel> class by using the specified model. |
![]() | ViewDataDictionary<TModel>(ViewDataDictionary) | Initializes a new instance of the ViewDataDictionary<TModel> class by using the specified view data dictionary. |
| Name | Description | |
|---|---|---|
![]() | Count | Gets the number of elements in the collection.(Inherited from ViewDataDictionary.) |
![]() | IsReadOnly | Gets a value that indicates whether the collection is read-only.(Inherited from ViewDataDictionary.) |
![]() | Item[String] | Gets or sets the item that is associated with the specified key.(Inherited from ViewDataDictionary.) |
![]() | Keys | Gets a collection that contains the keys of this dictionary.(Inherited from ViewDataDictionary.) |
![]() | Model | Gets or sets the model. |
![]() | ModelMetadata | Gets or sets information about the model.(Overrides ViewDataDictionary.ModelMetadata.) |
![]() | ModelState | Gets the state of the model.(Inherited from ViewDataDictionary.) |
![]() | TemplateInfo | Gets or sets an object that encapsulates information about the current template context.(Inherited from ViewDataDictionary.) |
![]() | Values | Gets a collection that contains the values in this dictionary.(Inherited from ViewDataDictionary.) |
| Name | Description | |
|---|---|---|
![]() | Add(KeyValuePair<String, Object>) | Adds the specified item to the collection.(Inherited from ViewDataDictionary.) |
![]() | Add(String, Object) | Adds an element to the collection using the specified key and value .(Inherited from ViewDataDictionary.) |
![]() | Clear() | Removes all items from the collection.(Inherited from ViewDataDictionary.) |
![]() | Contains(KeyValuePair<String, Object>) | Determines whether the collection contains the specified item.(Inherited from ViewDataDictionary.) |
![]() | ContainsKey(String) | Determines whether the collection contains an element that has the specified key.(Inherited from ViewDataDictionary.) |
![]() | CopyTo(KeyValuePair<String, Object>[], Int32) | Copies the elements of the collection to an array, starting at a particular index.(Inherited from ViewDataDictionary.) |
![]() | Equals(Object) | (Inherited from Object.) |
![]() | Eval(String) | Evaluates the specified expression.(Inherited from ViewDataDictionary.) |
![]() | Eval(String, String) | Evaluates the specified expression by using the specified format.(Inherited from ViewDataDictionary.) |
![]() | Finalize() | (Inherited from Object.) |
![]() | GetEnumerator() | Returns an enumerator that can be used to iterate through the collection.(Inherited from ViewDataDictionary.) |
![]() | GetHashCode() | (Inherited from Object.) |
![]() | GetType() | (Inherited from Object.) |
![]() | GetViewDataInfo(String) | Returns information about the view data as defined by the expression parameter.(Inherited from ViewDataDictionary.) |
![]() | MemberwiseClone() | (Inherited from Object.) |
![]() | Remove(KeyValuePair<String, Object>) | Removes the first occurrence of a specified object from the collection.(Inherited from ViewDataDictionary.) |
![]() | Remove(String) | Removes the element from the collection using the specified key.(Inherited from ViewDataDictionary.) |
![]() | SetModel(Object) | Sets the data model to use for the view.(Overrides ViewDataDictionary.SetModel(Object).) |
![]() | ToString() | (Inherited from Object.) |
![]() | TryGetValue(String, Object) | Attempts to retrieve the value that is associated with the specified key.(Inherited from ViewDataDictionary.) |
| Name | Description | |
|---|---|---|
![]() ![]() | IEnumerable.GetEnumerator() | Returns an enumerator that can be used to iterate through the collection.(Inherited from ViewDataDictionary.) |
You can use an instance of the strongly typed ViewDataDictionary<TModel> class in the same way that you use the loosely typed ViewDataDictionary class. An instance of the ViewDataDictionary<TModel> class is exposed by the ViewData property of the ViewPage<TModel> class.
To pass strongly typed data to a view, change the @ Page directive of the view so that the view inherits from ViewPage<TModel> instead of from ViewPage, as shown in the following example:
<%@ Page Inherits="ViewPage<Person>" %>
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.




