Dynamic change ViewStart layout path in MVC 3

前端 未结 4 2241
囚心锁ツ
囚心锁ツ 2021-02-10 07:42

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:18

    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";
    }
    

提交回复
热议问题