Shaun
Shaun

Reputation: 716

Dynamic ASP.NET MVC Routes

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?

Upvotes: 2

Views: 436

Answers (1)

Garry Shutler
Garry Shutler

Reputation: 32698

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.

Upvotes: 1

Related Questions