Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>In MVC 1, yes, temp data is lost after the next request after you store a key.</p> <p>With MVC 2 however, the temp data is lost after the first attempt to access it.</p> <p>You can always use Session, which TempData uses anyway, to solve the temp data loss issue your having.</p> <p><strong>From the MVC 2 Beta Release Notes:</strong></p> <blockquote> <p>TempDataDictionary Improvements</p> <p>The behavior of the TempDataDictionary class has been changed slightly to address scenarios where temp data was either removed prematurely or persisted longer than necessary. For example, in cases where temp data was read in the same request in which it was set, the temp data was persisting for the next request even though the intent was to remove it. In other cases, temp data was not persisted across multiple consecutive redirects.</p> <p>To address these scenarios, the TempDataDictionary class was changed so that all the keys survive indefinitely until the key is read from the TempDataDictionary object. The Keep method was added to TempDataDictionary to let you indicate that the value should not be removed after reading. The RedirectToActionResult is an example where the Keep method is called in order to retain all the keys for the next request.</p> </blockquote> <p>You can also look directly in the MVC 2 source to see these changes:</p> <p>MVC 1: </p> <pre><code> public object this[string key] { get { object value; if (TryGetValue(key, out value)) { return value; } return null; } set { _data[key] = value; _modifiedKeys.Add(key); } } </code></pre> <p>MVC 2:</p> <pre><code> public object this[string key] { get { object value; if (TryGetValue(key, out value)) { _initialKeys.Remove(key); return value; } return null; } set { _data[key] = value; _initialKeys.Add(key); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload