Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Web Api Controller subfolder routing

I’m going crazy here… this seems like a very simple task. First off, I know only the basics of the Web Api and MVC – so please don’t skewer me.

In the project I need to logically create controller subfolders (for organization purposes). I had a feeling it wasn’t as simple as I thought. I have the default route like this:

config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );

Which works as it should directly from the controllers folder in my project. I have added a subfolder in the controllers folder controllers/reports. I have searched quite a bit and just can't quite find a solution. How can I add a route that will direct to the subfolder. I have tried:

 config.Routes.MapHttpRoute(
            name: "ReportingApi",
            routeTemplate: "api/Reports/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }

and:

 config.Routes.MapHttpRoute(
            name: "ReportingApi",
            routeTemplate: "api/Reports/{id}",
            defaults: new { controller = "userunit" id = RouteParameter.Optional }
like image 772
Mike Schwartz Avatar asked Oct 09 '13 20:10

Mike Schwartz


1 Answers

Nevermind I'm an idiot... I left the default route in, removed the "Reports" in the url. It found the controller even though it was in a subfolder.

like image 74
Mike Schwartz Avatar answered Oct 21 '22 12:10

Mike Schwartz