Html.ActionLink erroneously picks up the current RouteValues

So I have a Route (e.g. ~/Help/FAQ). Now, if I am on any page other than the FAQ, Html.ActionLink works as I would expect.

@Html.ActionLink("FAQ", "FAQ", "Help", routeValues:=Nothing, htmlAttributes:=Nothing)

But if the current browser URL is the FAQ page with the id route attribute specified, http://www.example.com/Help/FAQ/56832, then the ActionLink above picks up the current routeVaues and renders the link with the 56832 attached - even though I am specifically telling the ActionLink that I do not want any routeValues to be rendered.

Is this a bug or am I doing something wrong?

Answers


You are not doing anything wrong, ASP.NET MVC implicitly uses the current route values in HTML helpers. You will have to overwrite them:

In C#:

@Html.ActionLink("FAQ", "FAQ", "Help", new { id = null }, null)

In VB.NET:

@Html.ActionLink("FAQ", "FAQ", Help", routeValues:= New With {.id = Nothing}, htmlAttributes:=Nothing)

Need Your Help

PHPmailer - CC from dropdown

php wordpress phpmailer

New to PHP and have found myself building a custom contact form for a client.