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

时间:2012-12-08 14:29:33

标签: asp.net-mvc-3

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

这是我的控制器

 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]'.

1 个答案:

答案 0 :(得分:1)

也许你的主视图中有一部分:

@Html.Partial("SomePartial")

此部分内容强烈输入IEnumerable<contents>

@model IEnumerable<icerik.Models.contents>

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

所以总是指定正确的模型:

@Html.Partial("SomePartial", SomeModelInstance)
相关问题