asp.net-mvcactionlink

asp.net mvc Html.ActionLink() keeping route value I don't want


I have the following ActionLink in my view

<%= Html.ActionLink("LinkText", "Action", "Controller"); %>

and it creates the following URL http://mywebsite.com/Controller/Action

Say I add an ID at the end like so: http://mywebsite.com/Controller/Action/53 and navigate to the page. On this page I have the markup I specified above. Now when I look at the URL it creates it looks like this:

http://mywebsite.com/Controller/Action/53 (notice the addition of the ID)

But I want it to remove the ID and look like it did originally, like this http://mywebsite.com/Controller/Action (notice no ID here)

Any ideas how I can fix this? I don't want to use hard coded URLs since my controller/actions may change.


Solution

  • The solution is to specify my own route values (the fourth parameter below)

    <%= Html.ActionLink("LinkText", "Action", "Controller", 
        new { id=string.Empty }, null) %>