2015-05-05 58 views
0

的模型项目我有MVC项目,其中Layoutstrongly 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模型?

+0

无论如何,为什么你需要一个布局'View'上的'Model'? – melancia

+2

从布局中删除模型定义。模型需要在视图中定义(您要告诉每个视图,它的模型必须是Dashboard) –

+2

可选(即_it是必须的),阅读[this](http://stackoverflow.com/questions/13225315/传递数据到布局认为,是常见到所有页)。 –

回答

0

一种方法是定义一个具有通用参数MainViewModel<T>的Viewmodel,并将它视为赞赏的T实例。然后,您可以使用Layout中的MainVewModel属性,并在视图中使用T的属性。

相关问题