I know this is something simple but I can't figure it out :(
I'm receiving this error:
The model item passed into the dictionary is of type 'System.Collections.Generic.List1[<>f__AnonymousType35[System.String,System.String,System.String,System.Nullable1[System.DateTime],System.String]]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable1[MvcApplication3.Order]'.
Here is the code for my controller:
var query = from o in db.Orders
join c in db.Customers on o.CustomerID equals c.CustomerID
where o.CustomerID == q
select new
{
o.CustomerID,
o.ShipAddress,
o.ShipCity,
o.ShippedDate,
c.ContactName
};
/*
var query = from o in db.Orders
where o.CustomerID == q
select o;
*/
return View(query.ToList());
Here is my view:
@model IEnumerable<MvcApplication3.Order>
@{
ViewBag.Title = "Search";
}
<h2>Search</h2>
Your search results contains @Model.Count() rows
<table>
<tr>
<td>Customer ID</td>
<td>Address</td>
<td>City</td>
<td>Shipped to Date</td>
</tr>
@foreach (var item in Model)
{
<tr>
<td>@item.CustomerID</td>
<td>@item.ShipAddress</td>
<td>@item.ShipCity</td>
<td>@item.ShippedDate</td>
<td>@item.Customer.ContactName</td>
</tr>
}
</table>
I'm assuming it has something to do with the way View is setup. If I remove the return View() and just loop through the data from the controller I get the results I expect. Any help would be greatly appreciated.
Thanks in advance!