I have started using MVC 3 and I really like working with it. It’s a much better experience than WebForms on so many levels.
However I have a question about the ViewBag (the new ViewData)
I am very careful to stick to sound modeling practices where I tend to put everything my view needs into ViewModels. However as far as the ViewBag goes, are there any concerns other than poor modeling practice that suggests that ViewBag should be uses sparingly? I don’t use it much myself, but a team mate asked the question today, and I could only recommend to limit its use since it’s a weakly typed model,hacked to be cool using dynamic (sudo typed)
Form what I can tell there shouldn’t be any performance impact from using it though?
Am I right? It’s just another object that get’s applied to the view server-side.
I am not counting any performance impact of using dynamic (if there is one that can be measured)
What are your views on disadvantages (or even advantages) of using the ViewBag?
For me, the big problem is that ViewBag isn’t type-safe and can easily produce run-time errors if you aren’t careful.
A view bag is really just a convenience to prevent simple cases where you would otherwise need a new viewmodel. I routinely use them, but only for very simple data.