views:

52

answers:

2

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:

 Order 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.

+5  A: 

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?

Darin Dimitrov
Thanks. The problem is that our developers get annoyed going back and forth between the Views folder and the Controllers folders (and other folders, such as ViewModels and Mappers, which I'm going to consolidate either way). They want to have them in one place so they can switch between everything related to an action quickly. They are coming from a webforms background, so I can understand to some degree. They love ASP.NET MVC, but are annoyed by their perceived inability to find things immediately.
Jess
Richard
Good tip, Richard - this will ease some of the pain (At least until I convince my boss to spend some money on a Resharper licence)
belugabob
+1  A: 

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

belugabob