问题
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.
来源:https://stackoverflow.com/questions/6858723/lifetime-of-viewbag-elements-in-asp-net-mvc3