0

It seems like that the default RazorViewEngine in the asp.net mvc 5 framework, only look for EditorTemplate in a folder named EditorTemplate inside the Shared folder. I am okay with that convention, the only thing I would like to add it search for EditorTemplate in the Shared/EditorTemplates and any folder inside if I place my EditorTemplate in ~/Views/Shared/EditorTemplates/SomeNewFolder it would still find it.

How can I extend the RazorViewEngine to tell razor to recursively look for any folder inside the EditorTemplates folder when searching for EditorTemplate?

Junior
  • 11,602
  • 27
  • 106
  • 212
  • You want it to search whatever folder structure you create or provide the folders it has to search? – DavidG Apr 19 '18 at 21:03
  • Basically look inside the `~/Views/Shared/EditorTemplates` folder and any other folder inside of it – Junior Apr 19 '18 at 21:05
  • I would strongly recommend against that. For a start the view engine system is designed to use a predefined list, even though you could fudge it to be dynamic. However the main reason is that this could affect your site performance as it needs to search the folder structure. – DavidG Apr 19 '18 at 21:06
  • I would agree if there were lots of folders. The idea is to allow me to have couple sub folder to separate my editor templates. Having many editor templates in one folder is messy. – Junior Apr 19 '18 at 21:46
  • It doesn't really matter how many folders, the act of scanning in the first place is expensive. If you only have a couple of folders though, why not just add them to the list? – DavidG Apr 19 '18 at 21:49
  • Note the the view engine also searches in `/Views/ControllerName/EditorTemplates/` by default –  Apr 19 '18 at 21:51
  • @DavidG that’s not a bad idea. Can you please guid me on how to add a folder called DefaultTypes? – Junior Apr 19 '18 at 23:20
  • @StephenMuecke thank you for that tip. That may come in handy if the editor is explicitly used by one controller. – Junior Apr 19 '18 at 23:24
  • https://stackoverflow.com/questions/632964/can-i-specify-a-custom-location-to-search-for-views-in-asp-net-mvc – DavidG Apr 19 '18 at 23:44

0 Answers0