TempDataDictionary Class
Represents a set of data that persists only from one request to the next.
Inheritance Hierarchy
System.Object
System.Web.Mvc.TempDataDictionary
Namespace: System.Web.Mvc
Assembly: System.Web.Mvc (in System.Web.Mvc.dll)
Syntax
'Declaration
<SerializableAttribute> _
Public Class TempDataDictionary _
Implements IDictionary(Of String, Object), _
ICollection(Of KeyValuePair(Of String, Object)), IEnumerable(Of KeyValuePair(Of String, Object)), _
IEnumerable, ISerializable
[SerializableAttribute]
public class TempDataDictionary : IDictionary<string, Object>,
ICollection<KeyValuePair<string, Object>>, IEnumerable<KeyValuePair<string, Object>>,
IEnumerable, ISerializable
[SerializableAttribute]
public ref class TempDataDictionary : IDictionary<String^, Object^>,
ICollection<KeyValuePair<String^, Object^>>, IEnumerable<KeyValuePair<String^, Object^>>,
IEnumerable, ISerializable
The TempDataDictionary type exposes the following members.
Constructors
Name | Description | |
---|---|---|
TempDataDictionary() | Initializes a new instance of the TempDataDictionary class. | |
TempDataDictionary(SerializationInfo, StreamingContext) | Initializes a new instance of the TempDataDictionary class. |
Top
Properties
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. |
Top
Methods
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 | Determines whether the specified Object is equal to the current Object. (Inherited from Object.) | |
Finalize | Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.) | |
GetEnumerator | Gets the enumerator. | |
GetHashCode | Serves as a hash function for a particular type. (Inherited from Object.) | |
GetObjectData | Populates a SerializationInfo class by using the data that is that is required to serialize the target object. | |
GetType | Gets the Type of the current instance. (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 | Creates a shallow copy of the current Object. (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 | Returns a string that represents the current object. (Inherited from Object.) | |
TryGetValue | Gets the value of the element that has the specified key. |
Top
Explicit Interface Implementations
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. | |
ISerializable.GetObjectData | Populates a SerializationInfo object by using the data that is that is required to serialize the target object. | |
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. |
Top
Remarks
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.
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.