Question

I'm stumped on what seems to be a very strange issue.

In my Razor markup, I have:

@Html.ActionLink("World", "Browse", "Destination")

But the HTML produced is:

<a href="/Destination/Browse/1/africa-middle-east">World</a>

Note that the additional data is, in fact, valid data that I'm using in other links. But why the heck does it show up here? I can even verify that the first line produces the second line by inspecting it in the debugger.

I know I'm doing something really stupid here. I just don't see what it is.

Was it helpful?

Solution

I guess, it is taking the old route values for building the a tag. check this article for a similar scenario.

Use this overload and try to explicitly pass null as RouteValues and see what changes it brings

public static MvcHtmlString ActionLink(
    this HtmlHelper htmlHelper,
    string linkText,
    string actionName,
    RouteValueDictionary routeValues
)

So your code can be re-written as

@Html.ActionLink("World", "Browse", "Destination",null)

Alternatively you may try to use this version also

<a href="Url.Action("Browser", "Destination")">World</a>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top