When will the values of the ViewBag
be flushed or cleared ?
The lifespan of TempData is rather unusual: It lives for one request only.
ViewBag will be slower than ViewData; but probably not enough to warrant concern.
In general, ViewBag is a way to pass data from the controller to the view. It is a type object and is a dynamic property under the controller base class. Compared to ViewData, it works similarly but is known to be a bit slower and was introduced in ASP.NET MVC 3.0 (ViewData was introduced in MVC 1.0).
Click your ViewBag. MyData and hit F9 . When debugging, once the break-point is hit, hover your mouse over the ViewBag to see its contents.
When you leave the view on subsequent request. ViewBag
is created in the controller and it will live until the rendering of the view. In addition to this it is something that I would not recommend you using and replace it with view models.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With