IntroductionToday, I am explaining about TempData vs ViewData vs Viewbag while working in MVC. Each one of the three (TempData, ViewData, ViewBag) terms are used to pass data from controller to View. These all have differing capacity to shield data while going from Controller to View using MVC application. In my recent articles, Explained thoroughly How to send SMS using C# and How to create charts using MVC.
- ViewBag is used logically to pass the data from controller to view.
- It is being introduced since C# 4.0 .Net Framework.
- ViewData is property of ControllerBase Class from .Net Framework 4.5 C# first time.
- ViewBag life reach is short. It just lies under current requesting.
- If it redirects then its value becomes null.
- It doesn't required to typecasting for getting data from Controller to View.
- ViewBag is slower than ViewData.