View Data View Bag Temp Data
ViewData is a dictionary object that is derived from ViewDataDictionary class. ViewBag is a dynamic property that takes advantage of the new dynamic features in C# 4.0. TempData is a dictionary object that is derived from TempDataDictionary class and stored in short lives session.
It’s required typecasting for getting data and check for null values to avoid error. It doesn’t required typecasting for getting data. It’s required typecasting for getting data and check for null values to avoid error.
ViewData is Faster than ViewBag ViewBag is slower than ViewData NA
ViewData is introduced in MVC 1.0 and available in MVC 1.0 and above ViewBag is introduced in MVC 3.0 and available in MVC 3.0 and above TempData is also introduced in MVC1.0 and available in MVC 1.0 and above
ViewData also works with .net framework 3.5 and above ViewBag only works with .net framework 4.0 and above TempData also works with .net framework 3.5 and above
Type Conversion code is required while enumerating In depth, ViewBag is used dynamic, so there is no need to type conversion while enumerating. Type Conversion code is required while enumerating

results matching ""

    No results matching ""