i wants to pass the data from my controller to view. here is code of controller
public ActionResult AllCars()
{
try
{
int id = System.Web.HttpContext.Current.User.Identity.GetUserId<int>();
var reservedCars = (from c in db.Cars
join o in db.Orders on c.Car_Id equals o.Car_Id
join u in db.AspNetUsers on o.Id equals u.Id
where u.Id == 5
select new
{
c.Car_Description,
c.Car_Id,
c.CarMakeId,
c.CarModelId,
c.Reservation_Status,
c.Color
});
return View(reservedCars);
}
catch (Exception)
{
throw;
}
}
here is my view file.
@model IEnumerable<FinalProject.Models.ReservedCar>
<table>
@foreach (var item in Model)
{
<tr>
<td>
@Html.DisplayFor(modelItem => item.Car_Id);
</td>
</tr>
}
</table>
but when i run my view i got following error The model item passed into the dictionary is of type 'System.Data.Entity.Infrastructure.DbQuery but this dictionary requires a model item of type 'System.Collections.IEnumerable`
i know im passing dbquery result to view and my view is expecting it will be iEnumerable. Please guide me how i can achieve thhis task.? i just wants to pass query results into my view and wants to use it.
ModelClass. ReservedCar.cs
namespace FinalProject.Models
{
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.Spatial;
public partial class ReservedCar
{
public int Id { get; set; }
public string Car_Description { get; set; }
public int Car_Id { get; set; }
public string CarMakeId { get; set; }
public string CarModelId { get; set; }
public string Reservation_Status { get; set; }
public string Color { get; set; }
}
}