Being on holidays gives me a lot of time to go through MVC questions on StackOverflow. And a lot of questions come from misusing of ViewBag
and ViewData
. A lot of people leave out Model from MVC and just slap all their data into ViewBag
. And this is bad.
I can understand why people are lazy: [sarcasm] creating an extra class can be very problematic, takes a lot of keystrokes [/sarcasm]. What people don’t realise is that ViewBag make them work harder.
ViewBag is a dynamic entity and it can contain any property it likes with any type it likes. So every time you do in controller something like this:
public ActionResult SomeViewBagAction()
{
ViewBag.SomeText = "blah";
return View();
}