hazem
hazem

Reputation: 505

ASP.NET MVC2 Routing Issue

i have two controllers with the same name in different sub folder My Controllers looks like

I want to access my first controller when the user requests http://mysite/api/User/Index

and access my second controller when the user requests http://mysite/help/User/Index

how to configure routing in Global.asax and how the views folders will look like?

will it look like?

Thanks and Regards.

Upvotes: 0

Views: 40

Answers (1)

Darin Dimitrov
Darin Dimitrov

Reputation: 1038710

You could use namespace constraints:

routes.MapRoute(
    "help",
    "help/{controller}/{action}",
    new { controller = "User", action = "Index" },
    new[] { "MvcApplication1.Controllers.help" }
);

routes.MapRoute(
    "api",
    "api/{controller}/{action}",
    new { controller = "User", action = "Index" },
    new[] { "MvcApplication1.Controllers.api" }
);

As far as having sub-folders for your Views is concerned, this is not supported out of the box. You will have to write a custom view engine for this to work.

By the way have you considered using Areas? They seem like better fit for your scenario. So you would define 2 areas: help and api and have the UserController defined in both.

Upvotes: 1

Related Questions