zoukankan      html  css  js  c++  java
  • MVC3.0自定义视图引擎(切换皮肤)

    在项目中可能根据不同的用户,不同的区域加载不同的界面风格,琢磨了一下终于搞定了。代码如下:

    public static void OnloadTemplate(string tempName)
            {
                RazorViewEngine engine = ViewEngines.Engines.Where(e => e is RazorViewEngine).Single() as RazorViewEngine;
                engine.ViewLocationFormats = engine.PartialViewLocationFormats = engine.MasterLocationFormats = new string[] {
                    "~/Views/" + tempName + "/{1}/{0}.cshtml",
                    "~/Views/" + tempName + "/{1}/{0}.vbhtml",
                    "~/Views/" + tempName + "/{1}/Shared/{0}.cshtml",
                    "~/Views/" + tempName + "/{1}/Shared/{0}.vbhtml",
                    "~/Views/" + tempName + "/Shared/{0}.cshtml",
                    "~/Views/" + tempName + "/Shared/{0}.vbhtml",
                    "~/Views/{1}/{0}.cshtml",
                    "~/Views/{1}/{0}.vbhtml",
                    "~/Views/Shared/{0}.cshtml",
                    "~/Views/Shared/{0}.vbhtml"
                };
            }

    然后在Global.asax中调用此方法

    protected void Application_Start()
            {
                AreaRegistration.RegisterAllAreas();

                RegisterGlobalFilters(GlobalFilters.Filters);
                RegisterRoutes(RouteTable.Routes);
                OnloadTemplate("Templet.en.us");//可以在web.config文件中配置
            }

    目录结构如下:

  • 相关阅读:
    【转】Android开发——MediaProvider源码分析(2)
    关于ActivityGroup使用过程中遇到的一点问题
    HttpWebRequest详解
    关于Assembly.CreateInstance()与Activator.CreateInstance()方法的区别
    你会在C#的类库中添加web service引用吗?
    ASP.NET跳转网页的三种方法的比较
    .net发送HTTP POST包
    依赖注入
    微软ASP.NET MVC Beta版本发布
    随笔~
  • 原文地址:https://www.cnblogs.com/yuhanzhong/p/2975558.html
Copyright © 2011-2022 走看看