From what I've read, information placed into TempData will be there for the current request and the next request (so that you can pass information across redirects). The problem is that if I browse to a controller action that does not redirect, the information in TempData will still be there for the next request. I'm using TempData to store informational messages that are displayed to the user, so now I'm getting the messages for the first screen on the second screen also.
Is there a good time in the controller lifecycle to clear out TempData once it's not used anymore?
Use ViewData instead of TempData if you are not redirecting. You should never need to clear TempData manually. If you only use it when redirecting, it will be cleared for you, automatically and at the correct time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With