What are the relationships between those (if there is any)?
它们之间的关系是什么(如果有的话)?
I know that ViewBag can access ViewData, except that ViewBag is of type Dynamic.
我知道ViewBag可以访问ViewData,但ViewBag是动态类型的。
In addition, ViewData is of type ViewDataDictionary.
此外,ViewData是ViewDataDictionary类型。
Can anyone elaborate more on these, especially the relationship between the ViewData
and a view's Model
@model
if there is one?
有谁能详细说明这些,特别是视图数据和视图的模型@model之间的关系吗?
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.
在进行了一些断点和调试之后,我才意识到视图的模型属性(razor的@model)与其视图数据之间没有关系。
UPDATE:
更新:
Actually, I take that back. A View's Model is actually part of ViewData
located in its ViewData.Model
实际上,我收回这句话。视图的模型实际上是位于其ViewData.Model中的ViewData的一部分
Now I'm just wondering about ViewData and ViewBag?
我想知道ViewData和ViewBag是什么?
1 个解决方案
#1
2
The single difference is that ViewBag uses the dynamic feature. As Darin Dimitrov said:
唯一的区别是ViewBag使用动态特性。季米特洛夫达林说过:
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).
它实现了与viewdata相同的目标,应该避免使用强类型的视图模型(应该避免使用与viewdata相同的方式)。
Take a look at here and at dtryon's link posted below your question.
看看这里和dtryon的链接贴在你的问题下面。
#1
2
The single difference is that ViewBag uses the dynamic feature. As Darin Dimitrov said:
唯一的区别是ViewBag使用动态特性。季米特洛夫达林说过:
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).
它实现了与viewdata相同的目标,应该避免使用强类型的视图模型(应该避免使用与viewdata相同的方式)。
Take a look at here and at dtryon's link posted below your question.
看看这里和dtryon的链接贴在你的问题下面。