6

I'm doing this:

@Url.Action("Details", "MyController", new { id = this.Model.ID })

The URLcomes out like this: /MyController/Details?id=1

How do I get it to format the URL like this: /MyController/Details/1

The routes look like this:

routes.MapRoute("Default", "{Controller}/{Action}", new { Controller = "Home", Action = "Index" });
routes.MapRoute("Default-ID", "{Controller}/{Action}/{ID}");

1 Answer 1

8

The order of routes matters - both urls are valid, and in this case the system gets to the query string one first when looking for a url matching that action.

There's also a possibility you have a case sensitivity issue with {ID} - not sure about that one, but generally it is best to use case consistently.

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

2 Comments

Thanks - the ordering was an oversight, oops! It works now with the proper order but the case apparently doesn't matter. I'll still use the same case in the route as I do elsewhere. Thanks.
Thanks Tom, I was having the same problem and I couldn't find the reason.

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.