, ViewBag, TempData


ViewData and ViewBag are used to transfer data from controller to view.

ViewData is nothing but a dictionary of objects and it is accessible by string as key.

ViewBag is very similar to ViewData. ViewBag is a dynamic property. ViewBag is just a wrapper around the ViewData.

TempData keeps data for the time of HTTP Request, which means that it holds data between two consecutive requests. TempData helps us to transfer data between controllers or between actions. Internally uses session.


  1. ViewData[key] = value;

  2. ViewBag.Key = value;

  3. TempData[key] = value;