When will the values of the ViewBag
be flushed or cleared ?
Lifetime of ViewBag elements in ASP.net MVC3
Asked Answered
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.
Why wouldn't you recommend ViewBag? because of it live until the rending of view ? –
Unreconstructed
Because it is much nicer to have a strongly typed ViewModel. Makes testing a lot easier. –
Schwa
Strongly type all the things! –
Jaggy
Dynamic vs static, it's just a preference thing –
Pension
If you want everything dynamic then go and use Ruby on Rails. Us C#'ers like our statically-typed goodness. :) –
Shrewish
© 2022 - 2024 — McMap. All rights reserved.