Dynamic change ViewStart layout path in MVC 3

前端 未结 4 644
不知归路
不知归路 2021-02-10 07:56

In my MVC project has 2 Areas which is Admin and Client and I need to dynamic config Layout for Client side, In _ViewStart (in client) file will set layout for all of client pag

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-10 08:33

    in Views/_ViewStart.cshtml

    @{    
    object multiTenant;
    if (!Request.GetOwinContext().Environment.TryGetValue("MultiTenant", out multiTenant))
    {
        throw new ApplicationException("Could not find tenant");
    }
    Layout = "~/Views/"+ ((Tenant)multiTenant).Name + "/Shared/_Layout.cshtml";
    }
    

提交回复
热议问题