TempDataDictionary Class
Represents a set of data that persists only from one request to the next.
Namespace: System.Web.Mvc
Assembly: System.Web.Mvc (in System.Web.Mvc.dll)
The TempDataDictionary type exposes the following members.
| Name | Description | |
|---|---|---|
![]() | Count | Gets the number of elements in the ICollection(T) object. |
![]() | Item | Gets or sets the object that has the specified key. |
![]() | Keys | Gets an ICollection(T) object that contains the keys of elements in the IDictionary(TKey, TValue) object. |
![]() | Values | Gets the ICollection(T) object that contains the values in the IDictionary(TKey, TValue) object. |
| Name | Description | |
|---|---|---|
![]() | Add | Adds an element that has the specified key and value to the IDictionary(TKey, TValue) object. |
![]() | Clear | Removes all items from the ICollection(T) instance. |
![]() | ContainsKey | Determines whether the IDictionary(TKey, TValue) instance contains an element that has the specified key. |
![]() | ContainsValue | Determines whether the dictionary contains the specified value. |
![]() | Equals | (Inherited from Object.) |
![]() | Finalize | (Inherited from Object.) |
![]() | GetEnumerator | Gets the enumerator. |
![]() | GetHashCode | (Inherited from Object.) |
![]() | GetType | (Inherited from Object.) |
![]() | Keep() | Marks all keys in the dictionary for retention. |
![]() | Keep(String) | Marks the specified key in the dictionary for retention. |
![]() | Load | Loads the specified controller context by using the specified data provider. |
![]() | MemberwiseClone | (Inherited from Object.) |
![]() | Peek | Returns an object that contains the element that is associated with the specified key, without marking the key for deletion. |
![]() | Remove | Removes the element that has the specified key from the IDictionary(TKey, TValue) object. |
![]() | Save | Saves the specified controller context by using the specified data provider. |
![]() | ToString | (Inherited from Object.) |
![]() | TryGetValue | Gets the value of the element that has the specified key. |
| Name | Description | |
|---|---|---|
![]() ![]() | ICollection(KeyValuePair(String, Object)).Add | Adds the specified key/value pair to the dictionary. |
![]() ![]() | ICollection(KeyValuePair(String, Object)).Contains | Determines whether a sequence contains a specified element by using the default equality comparer. |
![]() ![]() | ICollection(KeyValuePair(String, Object)).CopyTo | Copies a key/value pair to the specified array at the specified index. |
![]() ![]() | IEnumerable.GetEnumerator | Returns an enumerator that can be used to iterate through a collection. |
![]() ![]() | ICollection(KeyValuePair(String, Object)).IsReadOnly | Gets a value that indicates whether the dictionary is read-only. |
![]() ![]() | ICollection(KeyValuePair(String, Object)).Remove | Deletes the specified key/value pair from the dictionary. |
You can use a TempDataDictionary object to pass data in the same way that you use a ViewDataDictionary object. However, the data in a TempDataDictionary object persists only from one request to the next, unless you mark one or more keys for retention by using the Keep method. If a key is marked for retention, the key is retained for the next request.
A typical use for a TempDataDictionary object is to pass data from an action method when it redirects to another action method. For example, an action method might store information about an error in the controller's TempData property (which returns a TempDataDictionary object) before it calls the RedirectToAction method. The next action method can then handle the error and render a view that displays an error message.
.gif?cs-save-lang=1&cs-lang=fsharp)
.gif?cs-save-lang=1&cs-lang=fsharp)
.gif?cs-save-lang=1&cs-lang=fsharp)
.gif?cs-save-lang=1&cs-lang=fsharp)
.gif?cs-save-lang=1&cs-lang=fsharp)
.gif?cs-save-lang=1&cs-lang=fsharp)