What is TempData: TempData in ASP.Net MVC is dictionary object derived from TempDataDictionary. TempData class which retains the values for subsequent HTTP requests where as ViewBag and ViewData retains value only for the current request. Important Note: The important point here is TempData stores it values in session. In that case you may think What’s the difference between TempData in ASP.NET MVC and Session?” or “Why we have TempData dictionary object?, Why can’t we use the Session object directly?” The answer is simple. TempData gets destroyed sooner than the session object. That's whenever it is used(read) in subsequent HTTP request that is in the next controller then it will automatically get destroyed whereas session objects exists until we manuallyt destroys it. But if needed we can persist the tempdata for subsequent requests too. I will explain how to persist the tempdata in asp.net mvc in my next article. When we can use TempData? 1. TempData is mainly used
.Net Pickles
Asp.Net,C#.Net,SQL Server Articles, Source Codes and Examples