views:

211

answers:

2

I would like to create a sub folder in the controllers folder of an Asp.Net MVC application. But when ever I do this and try to navigate to a page the controler can not be found.

Here's a concrete example. Currently I have:

Controlers/UserAdminControler.cs
Controlers/PageAdminControler.cs
Controlers/MenuAdminControler.cs
Controlers/SomeOtherControler.cs
...

I want to organize it like this:

Controlers/Admin/UserAdminControler.cs
Controlers/Admin/PageAdminControler.cs
Controlers/Admin/MenuAdminControler.cs
Controlers/SomeOtherControler.cs
...

I found a way to create "Areas." This is a really nice idea and article but that is not really what I am looking for my site: http://haacked.com/archive/2008/11/04/areas-in-aspnetmvc.aspx

As well I have found that you can create sub folders in the Views directory (when you return View() you simply supply the path as a parameter). All I need now is to figure out how to add sub folders in the controllers directory.

+2  A: 

I just tried it, with no issues. I added a sub folder in my Controllers direcotry, and called it "SubFolder". There I added a Controller called "SubController". I then added a Folder in my views called Sub and added a View called Index. I then ran the app and navigated to:

http://localhost:2922/Sub/Index

with no problems. Maybe I'm misunderstanding your question, but there seems to be no issues with adding subfolders in the controllers folder.

BFree
I tried this and as long as your controller has the same name as the folder it appears to work. But if you add another controller call it "Sub2Controller" into SubFolder it doesn't work for me. Do I need to change the routes or anything?
scurial
Oops, there was a problem with my routing rules. It does work like you described.
scurial
@scurial So the problem wasn't that you spelled 'Controllers' wrong? ;-)
Simon_Weaver
+1  A: 

Take a look at S#arp Architecture. Billy has baked in the concept of areas already. You can find the information here: http://code.google.com/p/sharp-architecture/. You can also find the information to the google group there as well. It is very active and very supportive.

Alec Whittington