我需要使用模板文件 (.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"
这对我来说是一个更好的解决方案