gpt4 book ai didi

c# - 如何从 mvc 5 中的 Controller 更改布局(母版页)?

转载 作者:太空宇宙 更新时间:2023-11-03 15:13:48 25 4
gpt4 key购买 nike

我想更改应用程序的布局,在我的应用程序中有两种类型的用户 Admin 和 Member,admin member 可以登录。当从管理员以成员(member)身份登录时,我想将布局更改为成员(member)。这是我的代码

public ActionResult UserLogin(string email, int type)
{
#region SignOut Admin First
//signout First
if (Session["id"] != null)
{
UserLogBL ul = new UserLogBL();
UserLog lg = ul.GetByID(Convert.ToInt32(Session["id"]));
lg.logout = Convert.ToDateTime(System.DateTime.Now.ToLongTimeString());
ul.Update(lg);
}
Session.Clear();
Session.Abandon();
LmsSession.Abandon();
FormsAuthentication.SignOut();
#endregion

//getting user detail
LearnerBL learnerBL = new LearnerBL();
int id = learnerBL.GetIdBYName(email);
Learner learner = learnerBL.GetByID(id);
if (learner != null)
{
String role = LoginUser(learner);
if (string.Equals(role.ToLower(), "admin"))
return RedirectToAction("Index", "AdminDashboard");

return RedirectToAction("Index", "LearnerMyLearning");
}
return RedirectToAction("Login", "Account");
}

最佳答案

在各自的 View 中,您可以设置 View 应使用的布局。

@Layout="~/Views/Shared/LayoutNameHere.cshtml"

关于c# - 如何从 mvc 5 中的 Controller 更改布局(母版页)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39914523/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com