I am a student working on a mvc project to move a site from coldfusion to .net mvc. Were are also redesigning the site in the process so I am working with other team members, the design team members have a basic understanding of razor, but aren't expected to know any other parts of the framework.
I've always tried to use
ViewBag as little as possible, now even more so because the designers don't know what is in the
ViewBag when building the views, and get no intellisense.
Since working on this project I've moved to using the
ViewBag only in the baseController for the project adding properties in the
OnActionExecuted So that every view will have the same
ViewBag Properties. I've also tried to only use
ViewBag properties in layouts.
Since doing this I've wondered what are good reasons for ever adding to the ViewBag in a controller action directly before calling the view. I've come to appreciate that making more ViewModels while slightly more time helps to inform exactly what a view should be doing, as well as adds clarity.
I wanted to know when other people used
ViewBag where they found it appropriate and what they used to it for. I can't think of using it any time outside of a basecontroller now, I was hoping to get insight into other uses for the
ViewBag that perhaps I am just missing. Should I ever be adding to the ViewBag directly before calling an action, or should I create a more robust viewModel in these cases?