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

我有一套标准的模板用于我的mvc项目,我希望将其保存为源代码控制(SVN)中的外部文件夹 这意味着我无法将任何项目特定文件放在此文件夹中,因为它将被提交到错误的位置。 ..和我的标准模板需要覆盖MVC本身使用的模板,因此它们需要在MVC期望覆盖模板的位置(例如〜/ Views / Shared / EditorTemplates) 那我在哪里可以把我的项目特定的? 例如,我应该将它们放在〜/ Views / Shared / SiteEditorTemplates中,并添加搜索路径吗? 我该怎么办? 还是其他建议? 谢谢你,蚂蚁     
已邀请:
好的,我知道了 mvc中的编辑器代码在P​​artialViewLocationFormats中为引擎添加DisplayTemplates或EditorTemplates到路径中的编辑器。 所以,我在视图下创建了一条新路径 〜/查看/标准/ 并把我的标准东西放在那里 〜/查看/标准/ 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视图引擎和vb路径,但我还是不需要它们 这允许我在SVN中使用〜/ Views / Standard的外部,并在必要时覆盖项目内容 - rah!     
我个人将特定模板外部化为NuGet包,每次我启动一个新的ASP.NET MVC项目时,我只需导入这个NuGet包,并在各自的位置(
~/Views/Shared/EditorTemplates
)部署模板,以覆盖默认模板。     
您可以只更改现有的RazorViewEngine的PartialViewLocationFormats属性,而不是替换RazorView引擎(如Anthony Johnston所建议的那样)。此代码在Application_Start中:
System.Web.Mvc.RazorViewEngine rve = (RazorViewEngine)ViewEngines.Engines
  .Where(e=>e.GetType()==typeof(RazorViewEngine))
  .FirstOrDefault();

string[] additionalPartialViewLocations = new[] { 
  "~/Views/[YourCustomPathHere]"
};

if(rve!=null)
{
  rve.PartialViewLocationFormats = rve.PartialViewLocationFormats
    .Union( additionalPartialViewLocations )
    .ToArray();
}
    

要回复问题请先登录注册