问题描述
我如何删除VB剃刀引擎或配置RazorViewEngine不使用,并查找磁盘上的文件.vbhtml?对于新的ASP.NET MVC 3剃须刀项目,我总是删除的Application_Start的WebFormViewEngine,因为我永远不会使用它,所以我并不需要它来搜索磁盘上的.aspx,或名为.ascx文件名为.master。出于相同的原因,我想避免.vbhtml文件搜索。
How can I remove the VB Razor Engine or configure the RazorViewEngine to not use and look for .vbhtml files on disk? For new ASP.NET MVC 3 Razor projects, I always remove the WebFormViewEngine in Application_Start because I won't ever be using it and so I don't need it to search for .aspx, .ascx or .master files on disk. For this same reason I would like to avoid .vbhtml file searching.
推荐答案
这是code为自定义视图引擎:
This is the code for your custom view engine:
public class CSRazorViewEngine : RazorViewEngine {
public CSRazorViewEngine() {
base.AreaViewLocationFormats = new string[] {
"~/Areas/{2}/Views/{1}/{0}.cshtml",
"~/Areas/{2}/Views/Shared/{0}.cshtml"
};
base.AreaMasterLocationFormats = new string[] {
"~/Areas/{2}/Views/{1}/{0}.cshtml",
"~/Areas/{2}/Views/Shared/{0}.cshtml"
};
base.AreaPartialViewLocationFormats = new string[] {
"~/Areas/{2}/Views/{1}/{0}.cshtml",
"~/Areas/{2}/Views/Shared/{0}.cshtml"
};
base.ViewLocationFormats = new string[] {
"~/Views/{1}/{0}.cshtml",
"~/Views/Shared/{0}.cshtml"
};
base.PartialViewLocationFormats = new string[] {
"~/Views/{1}/{0}.cshtml",
"~/Views/Shared/{0}.cshtml"
};
base.MasterLocationFormats = new string[] {
"~/Views/{1}/{0}.cshtml",
"~/Views/Shared/{0}.cshtml"
};
}
}
此注册在Application_Start方法中是这样的:
Register this on Application_Start method like this:
ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new CSRazorViewEngine());
这篇关于让ASP.NET MVC 3的Razor视图引擎忽略.vbhtml文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!