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
ActionLink(HtmlHelper, String, String, String, String, String, String, Object, Object) Returns an anchor element (a element) for the specified link text, action, controller, protocol, host name, URL fragment, route values, and HTML attributes.
</a> ) tag by adding new attributes. By convention, the attribute names are prefixed with asp- . The rendered anchor element's href attribute value is determined by the values of the asp- attributes.
ActionLink is rendered as an HTML Anchor Tag (HyperLink) and hence it produces a GET request to the Controller's Action method which cannot be used to submit (post) Form in ASP.Net MVC 5 Razor.
The Anchor Tag Helper generates HTML anchor (<a> </a>) element by adding a new attribute. The "href" attribute of the anchor tag is created by using new attributes. The Anchor Tag Helper generates an HTML anchor (<a> </a>) element by adding new attribute.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With