Lifetime of ViewBag elements in ASP.net MVC3

2019-01-26 04:37发布

问题:

When will the values of the ViewBag be flushed or cleared ?

回答1:

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.