MVC3 System.Collections.Generic.List 传递错误的模型项



大家好,我已经检查了我的控制器,并查看似乎没有问题,但我收到系统组装错误。

这是我的控制器

 public ViewResult Index()
        {
            return View(db.banner.ToList());
        }

这是我的观点

{
@model IEnumerable<icerik.Models.banner>
}

我收到此错误

The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[icerik.Models.banner]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[icerik.Models.contents]'.

也许您的主视图中有部分:

@Html.Partial("SomePartial")

并且此部分被强类型化为IEnumerable<contents>

@model IEnumerable<icerik.Models.contents>

因此,请确保将正确的模型传递给此部分。如果您没有为部分帮助程序指定任何内容(如我的示例所示),则主模型将传递给此部分。

因此,请始终指定正确的模型:

@Html.Partial("SomePartial", SomeModelInstance)

最新更新