C# 从列表更改为IEnumerable

C# 从列表更改为IEnumerable,c#,asp.net-mvc,C#,Asp.net Mvc,我的应用程序停止并显示以下错误消息: The model item passed into the dictionary is of type 'System.Collections.Generic.List`1[Test.Models.GamesVM]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1 [Test.Models.Runner]'. 我的控

我的应用程序停止并显示以下错误消息:

The model item passed into the dictionary is of type
'System.Collections.Generic.List`1[Test.Models.GamesVM]', 
but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1
[Test.Models.Runner]'.
我的控制器:

return PartialView("PartialViewAllRunners", db.Runners.ToList());
我的看法是:

@Html.Partial("~/Views/Shared/PartialViewAllRunners.cshtml", Model)

视图
局部视图
都有
IEnumerable
,那么问题出在哪里,需要更改什么?

编辑-将视图模型更改为:

@模型IEnumerable<模型类名称>


返回视图(db.modelclass.ToList())

为您提供答案。消息是不言自明的-您将
GamesVM
的集合传递给一个需要
Runner
集合的视图(
IEnumerable
vs`List`与此无关)@StephenMuecke确定,因此我添加的任何局部视图都必须是同一个模型?不一定。您可以拥有一个包含
列表游戏
列表跑步者
属性的模型,然后使用(比如)
@Html.Partial(“Games”,model.Games)
和`@Html.Partial(“Runners”,model.Runners)`将它们传递给不同的部分。但是,您没有向我们展示足够的代码,无法准确地知道错误所在thrown@StephenMuecke所以,如果我理解你的意思是正确的,我可以在同一个视图中添加来自不同控制器和模型的多个局部视图?这正是我想做的。如果我尝试在视图中添加´…model.Games),Intellisense不会给我任何选项!如果顶部的视图主模型是视图模型,会有问题吗?我必须再检查一下我的代码。如果我没有显示足够的代码,我可以添加什么来更容易地看到问题?