次の方法で共有


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
Public method TempDataDictionary() Initializes a new instance of the TempDataDictionary class.
Protected method TempDataDictionary(SerializationInfo, StreamingContext) Initializes a new instance of the TempDataDictionary class.

Top

Properties

  Name Description
Public property Count Gets the number of elements in the ICollection<T> object.
Public property Item Gets or sets the object that has the specified key.
Public property Keys Gets an ICollection<T> object that contains the keys of elements in the IDictionary<TKey, TValue> object.
Public property Values Gets the ICollection<T> object that contains the values in the IDictionary<TKey, TValue> object.

Top

Methods

  Name Description
Public method Add Adds an element that has the specified key and value to the IDictionary<TKey, TValue> object.
Public method Clear Removes all items from the ICollection<T> instance.
Public method ContainsKey Determines whether the IDictionary<TKey, TValue> instance contains an element that has the specified key.
Public method ContainsValue Determines whether the dictionary contains the specified value.
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 Gets the enumerator.
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Protected method GetObjectData Populates a SerializationInfo class by using the data that is that is required to serialize the target object.
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Public method Keep() Marks all keys in the dictionary for retention.
Public method Keep(String) Marks the specified key in the dictionary for retention.
Public method Load Loads the specified controller context by using the specified data provider.
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method Peek Returns an object that contains the element that is associated with the specified key, without marking the key for deletion.
Public method Remove Removes the element that has the specified key from the IDictionary<TKey, TValue> object.
Public method Save Saves the specified controller context by using the specified data provider.
Public method ToString Returns a string that represents the current object. (Inherited from Object.)
Public method TryGetValue Gets the value of the element that has the specified key.

Top

Explicit Interface Implementations

  Name Description
Explicit interface implemetationPrivate method ICollection<KeyValuePair<String, Object>>.Add Adds the specified key/value pair to the dictionary.
Explicit interface implemetationPrivate method ICollection<KeyValuePair<String, Object>>.Contains Determines whether a sequence contains a specified element by using the default equality comparer.
Explicit interface implemetationPrivate method ICollection<KeyValuePair<String, Object>>.CopyTo Copies a key/value pair to the specified array at the specified index.
Explicit interface implemetationPrivate method IEnumerable.GetEnumerator Returns an enumerator that can be used to iterate through a collection.
Explicit interface implemetationPrivate method ISerializable.GetObjectData Populates a SerializationInfo object by using the data that is that is required to serialize the target object.
Explicit interface implemetationPrivate property ICollection<KeyValuePair<String, Object>>.IsReadOnly Gets a value that indicates whether the dictionary is read-only.
Explicit interface implemetationPrivate method 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.

See Also

Reference

System.Web.Mvc Namespace