Enable anchor tag in ASP.NET MVC 5 ActionLink

I searched the Internet for an answer and tried Brad Wilson to offer a solution here: Including an anchor tag in ASP.NET MVC Html.ActionLink

However, this does not work for me.

Here is what I did:

In the Controller / Details / _PartialView file, I put the anchor tag:

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

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

In the 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 check the displayed HTML in Chrome, the link above is not what I would like:

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

I misunderstood something or changed usage from the moment of publication. I am using MVC 5 ASP.NET 4.5.

Relations Craig

+5
source share
2 answers

This is because you are telling the browser to scroll through the element with the anchor-point identifier , but in your element you only specified the name attribute. Try the following:

 <a id="anchor-point"></a> 
+3
source

Here is an example of ASP.NET MVC 5 ActionLink for the Home Controller, an index view with the anchor tag β€œwhatis”

  @Html.ActionLink(" What Is", "Index", "Home", null, null, "whatis", null, new { @class = "iconwhatis" }); 

Without an icon, it will be

 @Html.ActionLink(" What Is", "Index", "Home", null, null, "whatis", null, null); 

Here's a link to a blog that explains all this very well.

+2
source

Source: https://habr.com/ru/post/1208233/


All Articles