我可以添加到显示/ EditorTemplates搜索路径在ASP.NET MVC 3? [英] Can I Add to the Display/EditorTemplates Search Paths in ASP.NET MVC 3?

查看:123
本文介绍了我可以添加到显示/ EditorTemplates搜索路径在ASP.NET MVC 3?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一组标准的为我的MVC项目模板,我想保留在我的源代码控制(SVN)的外部文件夹

I have a standard set of templates for my mvc projects which I want to keep as an external folder in my source control (SVN)

这意味着,我不能把任何项目的具体文件,此文件夹中,因为它会被提交到错误的地方..
..和我的标准模板,需要覆盖由MVC框架本身使用,以便他们需要的地方MVC的那些期望压倒一切的模板(例如〜/查看/共享/ EditorTemplates)

This means that I cannot put any project specific files in this folder as it will be committed to the wrong place.. .. and my standard templates need to override the ones that are used by MVC itself so they need to be in the place MVC expects overriding templates (e.g. ~/Views/Shared/EditorTemplates)

那么,我可以把我的项目特定的?

So where can I put my project specific ones?

我应该把它们放在〜/查看/共享/ SiteEditorTemplates,例如,和路径添加到搜索?
我会怎么做呢?
或其他建议?

Should I put them in ~/Views/Shared/SiteEditorTemplates, for example, and add the path to the search? How would I do that? Or an other suggestions?

感谢您,蚂蚁

推荐答案

好,知道了。

该编辑器code MVC中查找在PartialViewLocationFormats为发动机添加DisplayTemplates或EditorTemplates到路径编辑器。

The editor code in mvc looks for editors in the PartialViewLocationFormats for the engine adding DisplayTemplates or EditorTemplates to the path.

所以,我创建了下意见了一条新路
〜/查看/标准/

So, I have created a new path under views ~/Views/Standard/

和屁股我的标准的东西在里面
〜/查看/标准/ EditorTemplates / string.cshtml

And plopped my standard stuff in there ~/Views/Standard/EditorTemplates/string.cshtml

现在,注册在发动机的新路径在Global.asax中的Application_Start

Now, register the new path in the engine in global.asax Application_Start

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

    RegisterGlobalFilters(GlobalFilters.Filters);
    RegisterRoutes(RouteTable.Routes);

    ViewEngines.Engines.Clear();
    var viewEngine = new RazorViewEngine {
        PartialViewLocationFormats = new[]
        {
            "~/Views/{1}/{0}.cshtml",
            "~/Views/Shared/{0}.cshtml",
            "~/Views/Standard/{0}.cshtml"
        }
    };

    ViewEngines.Engines.Add(viewEngine);
}

请注意,这将摆脱Web表单的视图引擎和VB中的路径,但我并不需要他们无论如何

Note this will get rid of the webforms view engine and the vb paths, but I don't need them anyway

这让我有一个外部的〜/查看/标准SVN和项目的东西,如果有必要重写 - !RAH

This allows me to have an external for the ~/Views/Standard in SVN and for the project stuff to override if necessary - rah!

这篇关于我可以添加到显示/ EditorTemplates搜索路径在ASP.NET MVC 3?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆