We are currently using the default folder structure for our MVC app, and were wondering if it is possible to instead put a Controller and its related views into the same folder.
For example, a subset of our current structure is:
Model folder
OrderViewModel.cs
Views folder
OrderView.aspx
OrderGrid.ascx
OrderHeader.ascx
Controllers folder
OrderController.cs
Desired:
O开发者_JS百科rder folder
OrderController.cs
OrderGrid.ascx
OrderHeader.ascx
OrderViewModel.cs
OrderView.aspx
We have hundreds of actions/views, and they're currently grouped into too few controllers. This is partly because it becomes a pain to navigate around the project when flipping back and forth between a view and its related classes. The above solution would allow a developer focusing on one controller action to have all of them easily accessible.
I guess Areas could help with this too, but we'd have to make ~100 areas (one per set of closely related screens) to make this useful from my team's POV.
The default controller factory uses reflection to find all classes that derive from Controller
, so no matter in which folder you put them, as long as they are public and derive from Controller
it will work. But IMHO mixing views and controllers into the same folder is not a good idea. If it is a matter of organizing your controllers why not create subfolders in the Controllers
folder?
I'm not sure that diverging from convention is a good idea, as people are probably used to the standard folder layout - but I do feel your pain.
Navigation between files would be less painful if Visual Studio had some more of the features found in IntelliJ IDEA.
The fact is, pretty much any folder structure will degrade over time, as more files are added to the project, and better tools are usually a more efficient solution to the problem.
To be fair, it looks like VS2010 is starting to take some of the IntelliJ ideas on board, so things will probably improve - but there's a long way to go before Microsoft catch up.
EDIT: I forgot to mention that there is a plugin that provides lots more functionality for Visual Studio - pretty much bringing it up to the same level as IntelliJ
精彩评论