0
votes

My default routing follows {controller}/{id}/{action} instead of the standard {controller}/{action}/{id}

Now i need to set up the defaults such that if no id is provided, default to Index action in controller

If Id is provided and no action is provided, default to Detail action

If both Id and Action is provided then route to the corresponding action.

How can I set up this routing?

currently:

routes.MapRoute(
       name: "Default",
       url: "{controller}/{id}/{action}",
       defaults: new { controller = "projects", action = "Index" })
1

1 Answers

0
votes

The usual approach would be to set up the routing just like you specified; i.e. create the following routes in order:

  • {controller}/
  • {controller}/{id}/
  • {controller}/{id}/{action}

Evidently, for the various routes, there are no optional parameters anymore. Apply defaults as usual. :)