自定义RazorViewEngine会出现页面错误

Ken*_*130 7 razor asp.net-mvc-3

我正在尝试使用Razor实现自定义视图引擎.目标是如果视图位于子文件夹中以使用该视图.

我的视图引擎来自RazorViewEngine

 public class RazorViewFactory : RazorViewEngine
{
public RazorViewFactory()
{
    string TenantID = ConfigurationManager.AppSettings["TenantID"];

    if (TenantID != null)
    {
        MasterLocationFormats = new[] { 
            "~/Views/Shared/{0}.cshtml" 
        };

        ViewLocationFormats = new[]{
            "~/Tenant/" + TenantID + "/Views/{1}/{0}.cshtml",
            "~/Tenant/" + TenantID + "/Views/Shared/{0}.cshtml",
            "~/Views/{1}/{0}.cshtml",
            "~/Views/Shared/{0}.cshtml"
        };

        PartialViewLocationFormats = new[] { 
            "~/Tenant/" + TenantID + "/Views/{1}/{0}.cshtml", 
            "~/Tenant/" + TenantID + "/Views/Shared/{0}.cshtml" 
        };
    }
}
Run Code Online (Sandbox Code Playgroud)

}

在我的Global.asax中

 protected void Application_Start()
        {
            ...
            ViewEngines.Engines.Clear();
            ViewEngines.Engines.Add(new RazorViewFactory()); 
        }
Run Code Online (Sandbox Code Playgroud)

一切正常,除非我加载我的租户子视图主页,我得到以下错误.

The view at '~/Tenant/TenantB/Views/Home/Index.cshtml' 
must derive from WebViewPage, or WebViewPage<TModel>.
Run Code Online (Sandbox Code Playgroud)

如果我加载基本主页,它可以与Razor引擎一起使用.

mar*_*ind 21

您需要将web.config文件Views夹中的文件复制到您的Tenant文件夹中(或确保它具有与此处所述相同的配置部分:Razor HtmlHelper Extensions(或其他视图命名空间)未找到)