Ant*_*ton 15 mvc-editor-templates editortemplates asp.net-mvc-3
我有一套标准的模板用于我的mvc项目,我希望将其保存为源代码控制(SVN)中的外部文件夹
这意味着我不能将任何项目特定文件放在这个文件夹中,因为它将被提交到错误的地方.. ..我的标准模板需要覆盖MVC本身使用的那些,所以他们需要在MVC的位置期望重写模板(例如〜/ Views/Shared/EditorTemplates)
那我在哪里可以把我的项目特定的?
例如,我应该将它们放在〜/ Views/Shared/SiteEditorTemplates中,并添加搜索路径吗?我该怎么办?还是其他建议?
谢谢你,蚂蚁
Ant*_*ton 20
好的,我知道了
mvc中的编辑器代码在PartialViewLocationFormats中为引擎添加DisplayTemplates或EditorTemplates到路径中查找编辑器.
所以,我在视图下创建了一个新路径〜/ Views/Standard /
并在那里填写我的标准内容〜/ 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);
}
Run Code Online (Sandbox Code Playgroud)
请注意,这将摆脱webforms视图引擎和vb路径,但我还是不需要它们
这允许我在SVN中使用〜/ Views/Standard的外部,并在必要时覆盖项目内容 - rah!
归档时间: |
|
查看次数: |
3265 次 |
最近记录: |