I'm working with MVC 4 with Linq to SQL and in my controller class I intend to obtain a List from a query that has several tables and show it into the view as a List where M is a model class:
In the controller I have this
public List<HomeViewModel> GetHomeViewModel()
{
dynamic ReservationDay = (from c in hutRes.Clients
join r in hutRes.Reservations on c.ID_Client equals r.FK_Client
join ht in hutRes.Hut_Types on r.FK_HutType equals ht.ID_Hut_Type
join tr in hutRes.Time_Reserves on r.FK_TimeReserve equals tr.ID_Time_Reserve
join tc in hutRes.Type_ClientIds on c.FK_TypeClientId equals tc.ID_Type_ClientId
where r.DateR == DateTime.Now
select new
{
r.ID_Reservation,
tc.ClientId,
Number = c.Number_ID,
c.Name,
c.Phone,
time = tr.TimeReserve,
ReservationDate = r.DateR
}).ToList();
return ReservationDay;
}
public ActionResult Index()
{
return View(GetHomeViewModel());
}
And in the view side I have this header:
@model List<HutReservation.ViewModel.HomeViewModel>
I'm having this error:
Can not implicitly convert type 'System.Collections.Generic.List<<>f__AnonymousType4 <int,string,short,string,string,string,System.DateTime,byte,string,short,string,string>>' in 'System.Collections.Generic.List<HutReservation.ViewModel.HomeViewModel>'
Can Anybody help me I'm really stuck here :(
HomeViewModel?