You can create root Features folder, create one folder for each of your features and Shared folder within it. Then you can add all files (controllers, models, views, scripts) related to a single feature to it's folder. If multiple features use same file you can it to Shared folder. This is how project structure may look like:
- App
- Features
- Orders
- OrdersController.cs
- Create.cshtml
- Create.js
- CreateModel.cs
- Edit.cshtml
- Edit.js
- EditModel.cs
- EditViewModel.cs
...
- Customers
...
- Shared
- _Layout.cshtml
- Error.cshtml
- _ViewStart.cshtml
- Web.config
- FeatureViewLocationRazorViewEngine.cs
...
- Web.config
In order to use Razor with this folder structure you need to create new view engine class inherited from RazorViewEngine
, set proper ViewLocationFormats
, MasterLocationFormats
, PartialViewLocationFormats
and add instance of your view engine to ViewEngines.Engines
collection. For sample implementation and it's usage check FEATURE FOLDERS IN ASP.NET MVC article by Tim G. Thomas.
If you want to use classes like Scripts
in your views you also need to import their namespaces. One way to do this is to copy Web.config file from old Views folder to Features folder. For another options check How do I import a namespace in Razor View Page? question.
For more information check following articles: