How do View @Model, ViewDataDictionary, ViewData and ViewBag relate to each other?

What is the relationship between them (if any)?

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

In addition, ViewData is of type ViewDataDictionary.

Can anyone describe in more detail this especially relationship between ViewData

and view Model

@model

if there is one?

UPDATE:

I just realized by doing some breakpoint and debugging that there is no relationship between the View property Model

(razor @model

) and itsViewData.

UPDATE:

Actually, I'm taking it. The view model is actually a part ViewData

located in itsViewData.Model

Now I'm just curious to see ViewData and ViewBag?

+3


source to share


1 answer


The only difference is that the ViewBag uses a dynamic function. As Darin Dimitrov said :

It achieves the same purpose as viewdata, and should be avoided in favor of using strongly typed view models (just like viewdata should be avoided).



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

+1


source







All Articles