2

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 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.