Emmmanuel FIADUFE

Emmmanuel FIADUFE

  • 783
  • 1.1k
  • 54.6k

System.Web.Mvc.SelectListItem

Aug 19 2023 10:39 PM

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<GuestHouseManagementSystem.ViewModel.BookingViewModel>' does not contain a definition for 'CustomerName' and no extension method 'CustomerName' accepting a first argument of type 'System.Collections.Generic.IEnumerable<GuestHouseManagementSystem.ViewModel.BookingViewModel>' could be found (are you missing a using directive or an assembly reference?)
Model

This is my controller code

public ActionResult RoomBooking()
{
    IEnumerable<SelectListItem> objBookingViewModel = new List<SelectListItem>();
    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<SelectListItem> ListOfRoom { get; set; }
}

Answers (2)