ASP.NET MVC EditorTemplate Support Folders

I am working on what I consider to be a great ASP.NET MVC website. Currently, there are about 100 editor templates (all for 1 controller), and this number will grow.

What I want to accomplish is to organize my views in order to facilitate their search and version. This "version" step is what makes the view multiply over time. You can think of this project as a Q / A application where exams are created and can be pulled out later. In principle, for this particular project, the views / EditorTemplates cannot really change once during the production process, so a new copy should be created for future use. Links to the old performance will still exist, making this exam look and act like a year ago. Similarly, new exams will automatically pick up the new version of the presentation and use this version. I would like to have this type of structure, but I have other ideas.

Views/Shared/EditorTemplates/Common Views/Shared/EditorTemplates/Common/v2 Views/Shared/EditorTemplates/Common/v3 Views/Shared/EditorTemplates/Department Views/Shared/EditorTemplates/Department/v2 

Note. Despite the fact that I will have versions for subdirectories, from which it follows that I will have several versions of the same model and template, new files will have a unique file name. In addition, I am also trying to use the Razor generator to compile my views. Not sure if this can be expanded to add additional EditorTemplate search paths or not.

+8
asp.net-mvc razor razorgenerator
source share
2 answers

The structure will not look there, instead use the local EditorTemplate folders, for example. Views/Department/EditorTemplates .

Editors' templates are arranged using the viewing engine, which first looks in ~/Views/{1}/{0}.cshtml , and then in ~/Views/Shared/{0}.cshtml .

For example, if the Department controller and the model is String , the infrastructure requests EditorTemplates/String , and the view mechanism looks in ~/Views/Department/EditorTemplates/String.cshtml and ~/Views/Shared/EditorTemplates/String.cshtml .

+14
source share

The maximum answer is a much more elegant and simple answer. If you do not want to do this and you want a lot of work, you can write your own ViewEngine .

+2
source share

All Articles