I'd like to define one MapRoute which can map two different routes to one action.
I have an action to create an address:
public class AddressesController : BaseController
{
public ActionResult Create()
{
...
}
}
Following two routes should map to the action:
/Addresses/Create -> To create a new address
/Projects/3/Addresses/Create -> To create a new address to the project with the id = 3
I tried the following MapRoute config to accomplish this, but didn't work:
routes.MapRoute(
name: "CreateAddress",
url: "{projects}/{projectId}/{controller}/{action}",
defaults: new { projects = "", projectId = UrlParameter.Optional, controller = "Addresses", action = "Create" },
constraints: new { project = "(Projects)?" });
With this config the route /Projects/3/Addresses/Create
is working but not /Addresses/Create
.