I am developing an asp mvc 5 website. I have 3 models which are appointments, consultations and contacts. now i want to display all the details of these 3 models in a view called userdetails. What i have done so far Created a view model
public class AllServices
{
public List<Contact> Contacts { get; set; }
public List<Appointment> Appointments { get; set; }
public List<Consultation> Consultations { get; set; }
}
Then created the controller action method
public ActionResult userdetails()
{
AllServices services = new AllServices();
services.Appointments = dbcontext.Appointments.ToList();
services.Consultations = dbcontext.Consultations.ToList();
services.Contacts = dbcontext.Contacts.ToList();
return View(services);
}
and in view i made
@model List<Astrology.ViewModels.AllServices>
....
@foreach(var item in Model)
{
@item.Appointments
}
but when i run the page iam getting an error like this
The model item passed into the dictionary is of type 'Astrology.ViewModels.AllServices', but this dictionary requires a model item of type 'System.Collections.Generic.List`1[Astrology.ViewModels.AllServices]'.
Can someone please help me with it. Iam stuck with this.