3

I have a requirement to render partial views using template files (.cshmtl) . The template file to be used for rendering will depend on a variety of parameters.

So the path may look like

~views/themes/student_themes/V1/Gen.cshtml or

~views/themes/student_themes/V2/Gen.cshtml or

~views/themes/teacher_themes/V1/Gen.cshtml or

~views/themes/student_themes/V2/Gen.cshtml or

Also V1 , V2 etc may go upto 20 Version directories

I have registered custom view path as

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();
        }
    }

However since I have many such view paths it will become unwieldy. Is there a way to define wild card path as "~/Views/themes/.*/.*/{0}.cshtml"

which is a better solution for me

4

0 に答える 0