Bill Jones
Bill Jones

Reputation: 701

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!

Upvotes: 7

Views: 6076

Answers (1)

manojlds
manojlds

Reputation: 301527

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

Upvotes: 8

Related Questions