我需要将多个模型传递给一个视图,并且我希望视图是强类型的(因此,如果我可以帮助它,我想在不使用将每个模型传递给 ViewBag 的情况下这样做)。
Public Class TestModels
Public Class TestDetail
Public firstModel As firstModelHere ' An entity
Public secondModel As secondModelHere ' An entity
Sub New()
firstModel = Nothing
secondModel = Nothing
End Sub
End Class
End Class
我在模型目录中拥有自己的独立文件。我将封装模型传递给我的视图,如下所示:
@ModelType Website.TestModels.TestDetail
@Html.LabelFor(Function(model) model.firstModel.userName)
@Html.LabelFor(Function(model) model.secondModel.lastName)
我在控制器中设置了 firstModel 和 secondModel 并将模型传递给查看。当我去编译我的项目时,我得到了几十个错误(见下文),我该如何解决这个问题?我只是希望能够从我的视图中访问封装在另一个类中的多个模型。提前致谢。
Error 134 'ViewBag' is not declared. It may be inaccessible due to its protection level.
Error 129 'Context' is not declared. It may be inaccessible due to its protection level.
Error 138 'Layout' is not declared. It may be inaccessible due to its protection level.
Error 131 sub 'Execute' cannot be declared 'Overrides' because it does not override a sub in a base class.
...