What is TempData?

Category: C SharpWhat is TempData?
Editor">Editor Staff asked 2 years ago

What is TempData?

1 Answers
Editor">Editor Staff answered 2 years ago
  • TempData is a dictionary object derived from the TempDataDictionary class.
  • TempData is used to pass data from the current request to a subsequent request, in other words in the case of redirection.
  • The life of a TempData is very short and it retains its value for a short period of time.
  • It requires typecasting for complex data type as I’ve used in my example:
  • @foreach (var item in (List<MVCSample.Models.EmpRegistration>)TempData[“EmployeeRegistration”])
  • You can retain its value using the Keep method for subsequent requests.
     
    Most Asked ASP.NET MVC Interview Questions and Answers