我的 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/