public class TabContainerVM
public class TabContainerVM
{
public IEnumerable tab { get; set; }
public IEnumerable tabcolumn { get; set; }
public IEnumerable tabrow { get; set; }
}
在Controller裡把資料自行加入到model裡後回傳
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
}
[Authorize]
public class HomeController : Controller
{
[AllowAnonymous]
public ActionResult Index()
{
ViewBag.Title = PublicFunction.WebSiteName;
return View();
}
public ActionResult Create()
{
return View();
}
}
以下是登出的完整程式碼
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Logout()
{
FormsAuthentication.SignOut();
Session.Abandon();
// clear authentication cookie
HttpCookie cookie1 = new HttpCookie(FormsAuthentication.FormsCookieName, "");
cookie1.Expires = DateTime.Now.AddYears(-1);
Response.Cookies.Add(cookie1);
// clear session cookie (not necessary for your current problem but i would recommend you do it anyway)
HttpCookie cookie2 = new HttpCookie("ASP.NET_SessionId", "");
cookie2.Expires = DateTime.Now.AddYears(-1);
Response.Cookies.Add(cookie2);
//FormsAuthentication.RedirectToLoginPage();
return RedirectToAction("Index", "Home", null);
}