Forum Thread: How to Pass Data from Action to Action and Action to View in Mvc?

ViewBag:- Is similar kind of dynamic variable in c#. Dynamic internally uses reflection and at runtime, it finds out what the data or property.By using viewbag on that you can define dynamic property and it creates a dynamic property on the fly also they cannot provide compile error.

ViewBag uses dynamic features that are added in c# 4.0 version.which allows dynamically add property.

It is used to pass data from a controller to view.Internally view bag properties are stored name-value pairs in viewdata dictionary.

ViewData:- Is a dictionary of objects that are stored and retrieved using as key

Both ViewBag and ViewData does not provide compile time error checking.You know error at runtime only.It is good practice to use strongly typed view models. Because strongly typed view models provide compile time error checking. TempData:-

Tempdata is used for passing data from controller to controller or action to action.

After first read or request completed it does not maintain that data. For maintaining data for the second request there is peek and keep methods present.


Be the First to Respond

Share Your Thoughts