I would like to make a list populate with vehicle makes using a stored procedure and Entity Framework but when it I get the following error:
The model item passed into the dictionary is of type 'System.Collections.Generic.List1[System.String]', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable1[VehicleInfo.Models.tblVehicle]'.
Model
public partial class tblVehicle
{
public string BrandName{ get; set; }
}
Controller
public ActionResult Index()
{
VehicleDBContext db = new VehicleDBContext();
var brandnames = db.prcGetMakes().ToList();
return View(brandnames);
}
View
@model IEnumerable<VehicleInfo.Models.tblVehicle>
<ul id="Makes">
@foreach (var item in Model)
{
<li>@item.BrandName.Distinct()</li>
}
</ul>
Stored Procedure
CREATE PROCEDURE [dbo].[prcGetMakes]
AS
BEGIN
SET NOCOUNT ON;
SELECT DISTINCT
UPPER(BrandName) BrandName
FROM
tblVehicle
ORDER BY
BrandName
END
There must be something amazingly obvious that I am missing but I can't seem to work it out.
Please Help!
db.prcGetMakes().ToList()? Is it a list of string ? then the error is self explanatory. Your view is strongly typed to a list oftblVehicle. With the current view code, you basically need to return a list oftblVehicleobjects.