2

I have a action link setup like so:

@Html.ActionLink("Orders", "Index", "Order")

When I am on the page http://mydomain.com/Order/Index/2 that action link becomes a link to the page that I am on. How do I make it always link to http://mydomain.com/Order/Index

1 Answer 1

2

That's because routing engine reuses route variables from the current request. To prevent it from happening, you should always supply value for route variable.

    //assuming that last /2 corresponds to route variable named id

    @Html.ActionLink("Orders", "Index", "Order", new {id = ""}, null)
Sign up to request clarification or add additional context in comments.

3 Comments

I tried null instead of new {id=""} previously but that didnt work
null means value is not supplied. It is default value in fact - that anonymous object is translated into RouteValueDictionary. And it returns null if the key was not found in it - so no difference if you supply null or do not supply value at all
This seems very counter-intuitive. I would not expect it to do this. I wonder if there's a way to configure the routing engine.

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.