I've inherited my first MVC project and it involves using MVC3 on top of Linq to SQL. I've been trying to find a way to generate a check box list based on a many to many relationship involving a cross table.
I have a systemFailureType table that maps to a SystemFailureProblem table via a cross table.
Here is my designer layout for the tables:
here my view model
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using XNet.Repository.Model;
namespace XNet.WebUI.Hotel.ViewModel
{
public class CheckFacilityVM
{
public int FacilityID { get; set; }
public string facilityName { get; set; }
public bool facilityAvailable { get; set; }
public virtual Facility facility { get; set; }
public virtual HotelFacility hotelfacility { get; set; }
}
}
here my controller
public ActionResult Facility()
{
ViewBag.hotel = _hotelService.GetByID(1).HotelName;
var model = db.Facilities
.Select(htl => new CheckFacilityVM
{
FacilityID = htl.FacilityID,
facilityName = htl.FacilityName,
facilityAvailable = htl.IsActive,
})
.ToList();
return View(model);
}
and here my constructor
public Facility ShowRoomFacility(int HotelID)
{
var x = (from d in db.Facilities
where d.FacilityID == HotelID
select d).FirstOrDefault();
return x;
}
how can i make this.....