Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Folders in Controllers directory in ASP.NET MVC 4

I'm kind of new to ASP.Net MVC 4. I'm working on an app that will have a lot of routes. With that in mind, I'm running into naming conflicts in my Controller. Because of this, I've decided that I want to split up my Controller into multiple controllers. In an attempt to keep things clean, I feel I have a need to put Controller classes in subdirectories within the Controllers directory. My questions are:

  1. Is this even an option? I can't seem to find any examples with this approach
  2. How do I register the Controllers that are in the subdirectories such that when I add routes in the RouteConfig.cs file, they leverage the controller that is in a subdirectory?

Thank you!

like image 957
Bill Jones Avatar asked Feb 03 '13 14:02

Bill Jones


1 Answers

Is this an option? Definitely. You can place the controllers wherever you want. MVC would automatically scan the assembly for controllers and it doesn't matter if they are placed only under Controllers.

If things get more complex, and you want better organization, you can leverage the concept of Areas in ASP.NET MVC - http://msdn.microsoft.com/en-us/library/ee671793(v=vs.100).aspx

like image 72
manojlds Avatar answered Oct 13 '22 00:10

manojlds