C# – Grouping controllers in Asp.NET MVC

asp.netasp.net-mvcc

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

Best Answer

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.