I've been following an ASP .NET MVC tutorial. I've a HomeController with the following Index action.
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);
}
my index view is strongly typed with
@model ICollection<OdeToFood.Models.Restaurant>
now this gives the error
The model item passed into the dictionary is of type '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?**
The tutorial in question is here with chapter "Using LINQ"