As an ASP.Net MVC developer, you may frequently involved with these terms like Tempdata, viewdata and viewbag. In this post, I’m going to discuss about what are they and what are the main difference between them.
ViewBag:
- ViewBag is dynamic in nature.
- There is no type casting needed.
- Life time lasts only for the current request.
View Data:
- ViewData is stored as a dictionary. You can store a value using a key.
- Type casting is needed, when you retrieve.
- Life time lasts only for the current request.
Tempdata:
- It’s also store the value using key.
- Need type casting when the stored value retrieved.
- The life time of tempdata is little bit tricky. It will be available till you read it first time. After you read it, it will be marked for deletion. So in the next request, it won’t available. However, you can extend it’s life time by using keep and peek method.
Hope this helps!
0 comments :