zoukankan      html  css  js  c++  java
  • ASP.NET MVC 动态设置模板

    在页面中添加如下代码(Page_PreInit事件代码中动态设置模板,前提是在页面Action中将用户信息存到ViewData["USER"]了):

        <script runat="server">
            //动态设置模板
            protected void Page_PreInit(object sender, EventArgs e)
            {
                switch (ViewData.Eval("USER.roleid").ToString())
                {
                    case "1": this.Page.MasterPageFile = "~/Views/Shared/SuperAdmin.Master";
                        break;
                    case "2": this.Page.MasterPageFile = "~/Views/Shared/Manager.Master";
                        break;
                    default: this.Page.MasterPageFile = "~/Views/Shared/Default.Master";
                        break;
                }
            }
        </script>
    
    
  • 相关阅读:
    ASP.NET初识4
    属性
    ASP.NET初识4
    ACCP6.0第九章练习
    ASP.NET初识1
    鼠标指针含义
    ASP.NET初识2
    第三部分
    ASP.NET初识3
    ASP.NET初识5
  • 原文地址:https://www.cnblogs.com/xuezhizhang/p/1786370.html
Copyright © 2011-2022 走看看