3

What are the relationships between those (if there is any)?

I know that ViewBag can access ViewData, except that ViewBag is of type Dynamic.

In addition, ViewData is of type ViewDataDictionary.

Can anyone elaborate more on these, especially the relationship between the ViewData and a view's Model @model if there is one?

UPDATE:

I just realized after doing some breakpointing and debugging that there is no relationship between a View's Model property (razor's @model) and its ViewData.

UPDATE:

Actually, I take that back. A View's Model is actually part of ViewData located in its ViewData.Model

Now I'm just wondering about ViewData and ViewBag?

Jan Carlo Viray
  • 11,856
  • 11
  • 42
  • 63
  • Might be interested in [this](http://brendan.enrick.com/post/Difference-Between-ViewBag-and-ViewData-in-MVC-3.aspx) – Davin Tryon Mar 28 '12 at 23:21

1 Answers1

2

The single difference is that ViewBag uses the dynamic feature. As Darin Dimitrov said:

It achieves the same goal as viewdata and should be avoided in favor of using strongly typed view models (the same way as viewdata should be avoided).

Take a look at here and at dtryon's link posted below your question.

Community
  • 1
  • 1
Kim Tranjan
  • 4,521
  • 3
  • 39
  • 38