5

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

Community
  • 1
  • 1
Craig Roberts
  • 171
  • 1
  • 4
  • 18
  • I understand that you expect `../Controller/Details/id#anchor-point`, what is the rendered HTML like with the above `@Html.ActionLink` syntax? – ekad Dec 03 '14 at 12:48

3 Answers3

3

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>
Mathew Thompson
  • 55,877
  • 15
  • 127
  • 148
3

Here is an example ASP.NET MVC 5 ActionLink to Home controller, Index view with anchor tag "whatis"

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

With out the icon it would be

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

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

jacko
  • 131
  • 7
0
<ul>
     @foreach (var item in Model)
     {
     <li>                                   
     <a href='@Url.Action("Login",new{id=item.id})'>@item.post_name</a>
      </li>
       }
  </ul>
R2Psoft
  • 19
  • 2