【发布时间】:2014-04-17 11:25:07
【问题描述】:
我一直在关注 ASP .NET MVC 教程。我有一个具有以下索引操作的 HomeController。
OdeToFoodDatabase _db = new OdeToFoodDatabase();
public ActionResult Index()
{
var query = _db.Restaurants.ToList();
var model = from r in _db.Restaurants
orderby r.Name ascending
select r;
return View(model);
}
我的索引视图是强类型的
@model ICollection<OdeToFood.Models.Restaurant>
现在这给出了错误
传入字典的模型项的类型为'System.Data.Entity.Infrastructure.DbQuery '1[OdeToFood.Models.Restaurant]', but this dictionary requires a model item of type 'System.Collections.Generic.ICollection '1[OdeToFood.Models.Restaurant]'.......
**this error goes away if I pass model.ToList() instead of model in View() function.
But the tutorial that I'm following passed model in View() function and the code was running. I remember myself that some days ago when i tried that it worked fine. Now why is this so?**
【问题讨论】:
-
返回视图(model.ToList());
-
@BrendanMcKee :请查看编辑
标签: c# sql sql-server asp.net-mvc asp.net-mvc-4