Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 736887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T07:39:24+00:00 2026-05-14T07:39:24+00:00

If I redirect to a new page passing TempData to initialise the page it

  • 0

If I redirect to a new page passing TempData to initialise the page it works fine, however if the user presses the refresh button in their browser the TempData is no-longer available.
Given this, is there any situation where TempData could be used reliably?
Or any way to remove or mitigate the problem of users refreshing?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T07:39:24+00:00Added an answer on May 14, 2026 at 7:39 am

    In MVC 1, yes, temp data is lost after the next request after you store a key.

    With MVC 2 however, the temp data is lost after the first attempt to access it.

    You can always use Session, which TempData uses anyway, to solve the temp data loss issue your having.

    From the MVC 2 Beta Release Notes:

    TempDataDictionary Improvements

    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.

    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.

    You can also look directly in the MVC 2 source to see these changes:

    MVC 1:

      public object this[string key] {
            get {
                object value;
                if (TryGetValue(key, out value)) {
                    return value;
                }
                return null;
            }
            set {
                _data[key] = value;
                _modifiedKeys.Add(key);
            }
        }
    

    MVC 2:

       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);
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the code required to redirect the browser to a new page with
Possible Duplicate: redirect to new page when i click on Cancel button in C#
I'm trying to figure out how to redirect to a new page (different application,
I need to permanent redirect some pages, and redirect the user to the new
I need to redirect to new html page when the website opens in IE
I'm looking to redirect users to a new page once the form has been
I'm trying to get a redirect to a new page once the primeface dialog
Which one is better when we want to redirect to a new page in
Example: In the main page cliked on a button (NEW), the page then will
I am trying to redirect to a new page using CakePHP redirect method but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.