zoukankan      html  css  js  c++  java
  • ASP.NET MVC 自定义view engine


    1. 先看下webformviewengine的构造函数:
    public WebFormViewEngine()
    {
        
    base.MasterLocationFormats = new string[] { "~/Views/{1}/{0}.master""~/Views/Shared/{0}.master" };
        
    base.ViewLocationFormats = new string[] { "~/Views/{1}/{0}.aspx""~/Views/{1}/{0}.ascx""~/Views/Shared/{0}.aspx""~/Views/Shared/{0}.ascx" };
        
    base.PartialViewLocationFormats = base.ViewLocationFormats;
    }

    base.ViewLocationFormats 可以看出view page为什么只能写在views文件夹下的原因了。所以我们只需要在新的view engine的构造函数中修改下base.ViewLocationFormats 路径即可。

    2. 下面是一个自定义的View Engine -- SkinSupportViewEngine,它需要继承WebFormViewEngine。

        public class SkinSupportViewEngine : WebFormViewEngine
        {
            public SkinSupportViewEngine()
            {
                string[] mastersLocation = new[]
                                               {
                                                   string.Format("~/skins/{0}/{0}.master",
                                                                 Utils.SkinName)
                                               };
                MasterLocationFormats = this.AddNewLocationFormats(new List<string>(MasterLocationFormats),
                                                                   mastersLocation);

                string[] viewsLocation = new[]
                                             {
                                                 string.Format("~/skins/{0}/Views/{{1}}/{{0}}.aspx",
                                                               Utils.SkinName),
                                                 string.Format("~/skins/{0}/Views/{{1}}/{{0}}.ascx",
                                                               Utils.SkinName)
                                             };
                ViewLocationFormats =
                    PartialViewLocationFormats = this.AddNewLocationFormats(new List<string>(ViewLocationFormats),
                                                                            viewsLocation);
            }

    ......

    }

    3. 最后还需要在Global 文件中注册新的View Engine

                ViewEngines.Engines.Clear();
                ViewEngines.Engines.Add(new SkinSupportViewEngine());


  • 相关阅读:
    Linux 的启动流程(转)
    HDU 4686 Arc of Dream (矩阵快速幂)
    自己编写jQuery动态引入js文件插件 (jquery.import.dynamic.script)
    Oracle job procedure 存储过程定时任务
    Spring3 整合MyBatis3 配置多数据源 动态选择SqlSessionFactory
    Spring3 整合Hibernate3.5 动态切换SessionFactory (切换数据库方言)
    Spring3.3 整合 Hibernate3、MyBatis3.2 配置多数据源/动态切换数据源 方法
    软件设计之UML—UML的构成[上]
    软件设计之UML—UML中的六大关系
    ActiveMQ 即时通讯服务 浅析
  • 原文地址:https://www.cnblogs.com/rickie/p/2024375.html
Copyright © 2011-2022 走看看