我有一个 MVC 项目,需要有 2 个不同的 View 文件夹。一个在~/Views/
,一个在~/Framework/Views/
。这是通过创建一个基于 razor 视图引擎的自定义视图引擎来完成的,如下所示:
public class MyViewEngine : RazorViewEngine
{
private static string[] AdditionalViewLocations = new[]{
"~/Framework/Views/{1}/{0}.cshtml",
"~/Framework/Views/{1}/{0}.vbhtml",
"~/Framework/Views/Shared/{0}.cshtml",
"~/Framework/Views/Shared/{0}.vbhtml"
};
public MyViewEngine()
{
base.PartialViewLocationFormats = base.PartialViewLocationFormats.Union(AdditionalViewLocations).ToArray();
base.ViewLocationFormats = base.ViewLocationFormats.Union(AdditionalViewLocations).ToArray();
base.MasterLocationFormats = base.MasterLocationFormats.Union(AdditionalViewLocations).ToArray();
}
}
问题是我想在 2 个 Views 文件夹中的每一个中使用不同的 _ViewStart.cshtml 文件(即~/Views/_ViewStart.cshtml
用于文件夹中的视图和文件~/Views/
夹中的视图),但是视图引擎只使用它找到的第一个是原始的。~/Framework/Views/_ViewStart.cshtml
~/Framework/Views/
~/Views/
这可能吗?
谢谢