I'am trying to view information from two tables in a view with the view model, but it does not work.
This gives two tables with information.
public class HeatImage
{
[Key]
public int ImageId { get; set; }
public string name { get; set; }
}
public class HeatingArea
{
[Key]
public int ID { get; set; }
public string Area { get; set; }
}
My viewmodel
public class HeatingAreaViewModel
{
public IEnumerable<HeatImage> heatingImage { get; set; }
public IEnumerable<HeatingArea> heatingArea { get; set; }
}
My controller
public ActionResult Index()
{
HeatingAreaViewModel mymodel = new HeatingAreaViewModel();
mymodel.heatingArea = db.HeatingAreas.ToList();
mymodel.heatingImage = db.HeatImages.ToList();
return View(mymodel);
}
And my view
@model IEnumerable<Project.Models.HeatingAreaViewModel>
@foreach (var item in Model)
{
<a href="~/folder/@item.heatingImage">@item.heatingArea</a>
}
Error
The model item passed into the dictionary is of type 'Project.Models.HeatingAreaViewModel', but this dictionary requires a model item of type 'System.Collections.Generic.IEnumerable`1[Project.Models.HeatingAreaViewModel]'.