【发布时间】:2013-04-14 02:05:46
【问题描述】:
我的每个视图都需要一个导航栏,该导航栏位于名为 _NavigationPartial 的局部视图中。此部分视图使用
@model IEnumerable<ProOptInteractive.Models.ProductCategory>
并且此导航栏需要它才能运行。但是,在我的某些视图中,我声明了其他模型,这些模型会覆盖部分视图中的模型,并且在尝试在浏览器中打开这些视图时会出现错误:
@model ProOptInteractive.Models.ProductCategory <!-- this is incompatible! -->
@Html.Partial("_NavigationPartial")
如何设置局部视图以忽略视图中的原始模型声明?
【问题讨论】:
-
这是令人困惑的 b/c 部分未绑定到父模型
-
这是错误:传入字典的模型项的类型为“ProOptInteractive.Models.ProductCategory”,但此字典需要类型为“System.Collections.Generic.IEnumerable`1 的模型项[ProOptInteractive.Models.ProductCategory]'。显然他们是绑定的:P
-
很奇怪。我知道它们不是因为我每天都使用局部。显然需要更多信息,但我不确定是什么...
标签: asp.net-mvc html asp.net-mvc-4