[Solved] For each loop with submitting form


The error message is self explanatory. You have this in your view

@model hotel.Models.RoomModel

but you pass an instance of System.Data.Entity.Infrastructure.DbQuery<Hotel.BusinessObject.Room> to your view because of this line of code in your controller

return View(roomService.GetRoomsByCategory(CategoryId, SelectedDate, NumberNights, NumberPeoples));

You need to pass an instance of RoomModel instead of System.Data.Entity.Infrastructure.DbQuery<Hotel.BusinessObject.Room>. I would suggest changing your controller code to below

public ActionResult ComfortLevelView(int NumberNights, int CategoryId, int NumberPeoples, DateTime SelectedDate)
{
    IRoomService roomService = new RoomService();
    var rooms = roomService.GetRoomsByCategory(CategoryId, SelectedDate, NumberNights, NumberPeoples);

    RoomModel model = new RoomModel();
    model.Rooms = rooms.ToList();

    return View(model);
}

7

solved For each loop with submitting form