Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc 传递到字典中的模型项的类型为。。。但此词典需要类型为的模型项_Asp.net Mvc - Fatal编程技术网

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'.