asp.net-mvc-3 - 我可以添加到 ASP.NET MVC 3 中的 Display/EditorTemplates 搜索路径吗?

标签 asp.net-mvc-3 editortemplates mvc-editor-templates

我的 mvc 项目有一组标准模板,我想将其作为源代码管理 (SVN) 中的外部文件夹保留

这意味着我不能在这个文件夹中放置任何项目特定的文件,因为它会被提交到错误的地方..
.. 我的标准模板需要覆盖 MVC 本身使用的模板,因此它们需要位于 MVC 期望覆盖模板的位置(例如 ~/Views/Shared/EditorTemplates)

那么我可以把我的项目特定的放在哪里呢?

例如,我应该将它们放在 ~/Views/Shared/SiteEditorTemplates 中,并将路径添加到搜索中吗?
我该怎么做?
或者其他建议?

谢谢你, Ant

最佳答案

好的,我知道了

mvc 中的编辑器代码在 PartialViewLocationFormats 中查找编辑器,以便引擎将 DisplayTemplates 或 EditorTemplates 添加到路径中。

所以,我在 View 下创建了一个新路径
〜/ View /标准/

把我的标准东西放进去
~/Views/Standard/EditorTemplates/string.cshtml

现在,在 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);
}

请注意,这将摆脱 webforms View 引擎和 vb 路径,但无论如何我都不需要它们

这使我可以为 SVN 中的 ~/Views/Standard 和项目内容在必要时覆盖一个外部 - 啊!

关于asp.net-mvc-3 - 我可以添加到 ASP.NET MVC 3 中的 Display/EditorTemplates 搜索路径吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5581786/

相关文章:

asp.net-mvc - 使用 Session 进行 Asp.net MVC3 长轮询

c# - 如何从 typeName 字符串转换为泛型?

kendo-grid - Kendo UI 网格与下拉编辑器模板编辑问题

asp.net-mvc - ViewBag.Title 值覆盖 ASP.NET MVC 编辑器模板的 Model.Title

c# - 有没有办法在 ASP.NET MVC3 中将编辑器和显示模板与 Dictionary<K,V> 一起使用?

c# - 为什么我们不应该将业务逻辑放在服务中?我们会更换我们的服务吗?

asp.net-mvc - knockout + mvc 3 + 验证

templates - 自定义 MVC2 编辑器模板

asp.net-mvc - EditorForModel - 使用 editorfor 时出现重复标签