2
我想改变应用程序的布局,在我的应用程序中有两种类型的用户Admin和Member,从admin member可以登录。我想从管理员登录成员时将布局更改为成员。 这里是我的代码如何从mvc 5中的控制器更改布局(主页)?
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");
}
在相应视图中可以设置'@布局= “〜/查看/共享/ LayoutNameHere.cshtml”' – Nkosi