0

I'm using the default routing below.

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

The problem is that it's very rigid. The default action will be Index in each case. (And the default controller will be Home.)

I'd like to route to action IndexHey when controller Uno is targeted and to action IndexHoopla when Duo is. What is the syntax for that?!

(I've played around with different additional route mappings but didn't got it to work and now I'm sick and tired of trial-and-erroring.)

1 Answer 1

1

The easiest approach is to have specific routes for specific controllers before generic one like

routes.MapRoute(
  name: "Uno",
  url: "Uno/{action}/{id}",
  defaults: new { controller = "Uno", action = "IndexHoopls", id = "17" }
routes.MapRoute(
  name: "Default",
  url: "{controller}/{action}/{id}",
  defaults: new { controller = "Home", action = "Index", id = "17" }
Sign up to request clarification or add additional context in comments.

2 Comments

Is it recommended to call both routings Default? I'd use Uno, Duo etc.
@KonradViltersten - copy-paste... I don't believe you can have duplicate names (can't check right now). Updated the sample.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.