我繼承了我的第一個MVC項目,它涉及在Linq to SQL之上使用MVC3。我一直在試圖找到一種基於涉及交叉表的多對多關係來生成複選框列表的方法。使用複雜視圖模型和交叉表生成複選框列表
我有一個systemFailureType表通過交叉表映射到SystemFailureProblem表。
這裏是我的表設計佈局:
我在這裏的視圖模型
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; }
}
}
這裏我控制器
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);
}
,在這裏我構造
public Facility ShowRoomFacility(int HotelID)
{
var x = (from d in db.Facilities
where d.FacilityID == HotelID
select d).FirstOrDefault();
return x;
}
我怎樣才能使這個.....