這功能看似簡單
但不知如何架構跟下語法可能會寫不出來
先在ViewModels裡建一個Class裡面有三個IEnumerable
public class TabContainerVM public class TabContainerVM { public IEnumerable在Controller裡把資料自行加入到model裡後回傳tab { get; set; } public IEnumerable tabcolumn { get; set; } public IEnumerable tabrow { get; set; } }
public ActionResult TabContainer() { var tab = from u in db.Tab select u; var tabcolumn = from u in db.TabColumn select u; var tabrow = from u in db.TabRow select u; var model = new TabContainerVM { tab = tab, tabcolumn = tabcolumn, tabrow = tabrow }; return PartialView("_TabContainer",model); }view的話就能使用
@model ViewModels.TabContainerVM參考網址 點我@foreach (var tab in Model.tab) {@foreach (var tab in Model.tabcolumn ) { //do something }
}