Asp.net mvc 传递到字典中的模型项的类型为。。。但此词典需要类型为的模型项
我有一个Asp.net mvc 传递到字典中的模型项的类型为。。。但此词典需要类型为的模型项,asp.net-mvc,Asp.net Mvc,我有一个MVC项目,它有一个布局,具有强类型模型,名为“仪表板” 此布局有一个呈现其余页面的RenderBody()方法 然后,在我的主页上,我有一个使用模型NewPatient强类型的视图 在控制器上,我有一堆代码,最终我将NewPatient模型传递给它 当我尝试运行此代码时,出现了一个名为: The model item passed into the dictionary is of type 'Dashboard_v2.Models.NewPatient', but this dict
MVC
项目,它有一个布局
,具有强类型
模型,名为“仪表板
”
此布局有一个呈现其余页面的RenderBody()
方法
然后,在我的主页上,我有一个使用模型NewPatient
强类型的视图
在控制器上,我有一堆代码,最终我将NewPatient
模型传递给它
当我尝试运行此代码时,出现了一个名为:
The model item passed into the dictionary is of type 'Dashboard_v2.Models.NewPatient', but this dictionary requires a model item of type 'Dashboard_v2.Models.Dashboard'.
如果我的页面具有强类型的NewPatient模型,为什么需要仪表板模型?一种方法是使用通用参数
MainViewModel
定义一个Viewmodel,并为视图使用它的实例。然后,您可以在布局中使用MainVewModel
属性,并在视图中使用T的属性。为什么在布局视图上需要模型
?从布局中删除模型定义。需要在视图中定义模型(您告诉每个视图其模型必须是仪表板
)(也就是说,它是必须的),阅读.ohh。。我懂了。。谢谢如果您希望在所有视图中呈现与仪表板
相关的一些详细信息,则在布局中使用@Html.Action()
调用子操作方法,该方法基于实例仪表板
The model item passed into the dictionary is of type 'Dashboard_v2.Models.NewPatient', but this dictionary requires a model item of type 'Dashboard_v2.Models.Dashboard'.