我需要使用模板文件(.cshmtl)呈现部分视图。用于渲染的模板文件将取决于各种参数。
所以路径可能看起来像
~views / themes / student_themes / V1 / Gen.cshtml或
~views / themes / student_themes / V2 / Gen.cshtml或
~views / themes / teacher_themes / V1 / Gen.cshtml或
~views / themes / student_themes / V2 / Gen.cshtml或
V1,V2等也可以达到20个版本目录
我已将自定义视图路径注册为
ViewEngines.Engines.Add(new TemplateViewEngine());
FreeSurvey.Web.Startup.DoStartup.Run();
}
}
class TemplateViewEngine : RazorViewEngine
{
private static string[] NewPartialViewFormats = new[] {
"~/Views/themes/theme_student/v2/{0}.cshtml" ,
"~/Views/themes/theme_student/v1/{0}.cshtml" ,
..
..
};
public TemplateViewEngine()
{
base.PartialViewLocationFormats = base.PartialViewLocationFormats.Union(NewPartialViewFormats).ToArray();
}
}
然而,由于我有许多这样的视图路径,它将变得笨拙。有没有办法定义
外卡路径为"~/Views/themes/.*/.*/{0}.cshtml"
对我来说这是一个更好的解决方案