是否可以在asp.net razor中处理.html文件,如.cshtml文件?
我想并排使用Webstorm和VS. (Webstorm用于html和js的东西,VS用于c#的东西)
答案 0 :(得分:2)
默认情况下,Razor引擎仅查找.cshtml
和.vbhtml
个文件。您可以通过定义从RazorViewEngine
继承的自定义ViewEngine并添加位置来搜索视图来更改此行为。
来自Make ASP.NET MVC 3 Razor View Engine ignore .vbhtml files:
public class CSRazorViewEngine : RazorViewEngine {
public CSRazorViewEngine() {
base.AreaViewLocationFormats = new string[] {
"~/Areas/{2}/Views/{1}/{0}.cshtml",
"~/Areas/{2}/Views/Shared/{0}.cshtml",
"~/Areas/{2}/Views/{1}/{0}.html",
"~/Areas/{2}/Views/Shared/{0}.html",
};
base.AreaMasterLocationFormats = new string[] {
"~/Areas/{2}/Views/{1}/{0}.cshtml",
"~/Areas/{2}/Views/Shared/{0}.cshtml",
"~/Areas/{2}/Views/{1}/{0}.html",
"~/Areas/{2}/Views/Shared/{0}.html",
};
base.AreaPartialViewLocationFormats = new string[] {
"~/Areas/{2}/Views/{1}/{0}.cshtml",
"~/Areas/{2}/Views/Shared/{0}.cshtml",
"~/Areas/{2}/Views/{1}/{0}.html",
"~/Areas/{2}/Views/Shared/{0}.html",
};
base.ViewLocationFormats = new string[] {
"~/Views/{1}/{0}.cshtml",
"~/Views/Shared/{0}.cshtml",
"~/Views/{1}/{0}.html",
"~/Views/Shared/{0}.html",
};
base.PartialViewLocationFormats = new string[] {
"~/Views/{1}/{0}.cshtml",
"~/Views/Shared/{0}.cshtml",
"~/Views/{1}/{0}.html",
"~/Views/Shared/{0}.html",
};
base.MasterLocationFormats = new string[] {
"~/Views/{1}/{0}.cshtml",
"~/Views/Shared/{0}.cshtml",
"~/Views/{1}/{0}.html",
"~/Views/Shared/{0}.html",
};
base.FileExtensions = new[]
{
"cshtml",
"html",
};
}
}
然后在Application_Start()
:
ViewEngines.Engines.Clear();
ViewEngines.Engines.Add(new CSRazorViewEngine());
或只是add .cshtml
to your Webstorm's configuration as File Type HTML。