What is difference between ViewData, ViewBag and TempData?

Total Post:83

Points:415
C#
 528  View(s)
Ratings:
Rate this:
  1. Post:83

    Points:415
    What is difference between ViewData, ViewBag and TempData?

    ViewData and ViewBag are almost similar,and TempData carry out additional responsibility.

    The main difference between ViewBag and ViewData is, ViewBag is a dynamic property that takes benefit of the new dynamic features in C# 4.0. And ViewData is a dictionary of objects that is derived from ViewDataDictionary class and is attainable using strings as keys.

    Now we Discuss about TempData,

    TempData helps to maintain data when you move from one controller to other controller or from one action to other action. TempData internally uses session variables.

Answer