Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When is it "acceptable" to use ViewBag/ViewData in ASP.NET MVC?

I realize that the best practice is to use strongly typed Views and pass in all needed data in a ViewModel, but I am curious if there are situations where it is actually considered "best practice" to pass data in the ViewBag/ViewData.

In what scenarios is the ViewBag/ViewData preferred for passing data to a view?

update

It's great to hear the various uses everyone has come up with for ViewBag/ViewData. We may never arrive at a "best practice" but it will be great to see the different solutions people have come up with that rely on the ViewBag/ViewData.

like image 353
stephen776 Avatar asked Apr 12 '11 15:04

stephen776


1 Answers

I use them rarely, for bits of information that are totally unrelated to the model or view model that I'm passing to the view, again, most of the times I use a view model

like image 86
BlackTigerX Avatar answered Sep 28 '22 04:09

BlackTigerX