Lifetime of ViewBag elements in ASP.net MVC3
Asked Answered
L

1

18

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

Liselisetta answered 28/7, 2011 at 12:9 Comment(0)
O
21

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.

Odd answered 28/7, 2011 at 12:10 Comment(5)
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 thingPension
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.