0
的模型项目我有MVC
项目,其中Layout
的strongly typed
模型名为“Dashboard
”。传入字典的模型项目类型是...但此字典需要
@model Dashboard_v2.Models.Dashboard
这个布局有一个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模型?
无论如何,为什么你需要一个布局'View'上的'Model'? – melancia
从布局中删除模型定义。模型需要在视图中定义(您要告诉每个视图,它的模型必须是Dashboard) –
可选(即_it是必须的),阅读[this](http://stackoverflow.com/questions/13225315/传递数据到布局认为,是常见到所有页)。 –