Hello Team,
I have encounter this error whiles using ViewModel
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS1061: 'System.Collections.Generic.IEnumerable
Model
This is my controller code
public ActionResult RoomBooking()
{
IEnumerable objBookingViewModel = new List();
var room = objHotelDbEntities.Rooms.ToList();
objBookingViewModel = room.Select(obj=>new SelectListItem
{
Text = obj.RoomNumber,
Value = obj.RoomId.ToString(),
Selected = false
}).ToList();
return View(objBookingViewModel);
}
Booking View Model
public class BookingViewModel
{
public string CustomerName { get; set; }
public string PhoneNo { get; set; }
public DateTime BookingFrom { get; set; }
public DateTime BookingTo { get; set; }
public int AssignRoomId { get; set; }
public int NoOfMembers { get; set; }
public decimal TotalAmount { get; set; }
public IEnumerable ListOfRoom { get; set; }
}
Tahir AnsariPosted Aug 20, 2023, 5:06 AM
it seems that you're passing a list of
SelectListItemto the view, but your ViewModelBookingViewModelhas properties such as "CustomerName", "PhoneNo", etc. These properties are not present in theSelectListItemclass.try below modified code
Emmmanuel FIADUFEPosted Aug 21, 2023, 10:46 AM
Thank you Ansari, it is working