tags:

views:

136

answers:

1

I have a requirement to dynamically change a ASP.NET MVC route depending on the contents of the URL.

For example:

routes.MapRoute(
  "Default",
  "{controller}/{action}/{id}/{value}",
  new { controller = "Home", action = "Index", id = 0, value = "" }
);

I'd like to use the above route for most scenarios but also allow {controller}/{value} in certain cases.

How can this be done with ASP.NET MVC?

+1  A: 

Off the top of my head you could apply some constraints to your rules. For example if value was always numeric and action was always made up of letters then you could use constraints to make the correct rules be selected. It really depends on what value and action could potentially be. It could be that you need to implement a custom routing rule.

Garry Shutler