Asp.net-mvc – Include anchor tag in ASP.NET MVC 5 ActionLink

asp.net-mvc

I have searched the web for an answer and tried Brad Wilson's suggested solution here:
Including an anchor tag in an ASP.NET MVC Html.ActionLink

However, this does not work for me.

Here's what I did:

In Controller/Details/_PartialView file I place an anchor tag:

<a name="anchor-point"></a>

The _PartialView file is obviously rendered when Controller/Details is rendered.

In Controller/Index I have an ActionLink as follows

<td>@Html.ActionLink("linkText", "Details", "Controller", null, null, "anchor-point", new { item => item.ID }, null)</td>

When I inspect the rendered HTML in Chrome the above link is not what I would, which is:

../Controller/Details/id#anchor-point

Have I misunderstood something or has usage changed since the original post. I am using MVC 5 ASP.NET 4.5.

Regards
Craig

Best Answer

That's because you're telling the browser to scroll to an element with an ID of anchor-point, yet your element you posted you have only set the name attribute. Try this:

<a id="anchor-point"></a>