在ASP.NET MVC 5 ActionLink中包含锚标记

时间:2014-12-03 12:38:28

标签: asp.net-mvc

我在网上搜索了答案,并尝试了Brad Wilson建议的解决方案: Including an anchor tag in an ASP.NET MVC Html.ActionLink

然而,这对我不起作用。

这就是我的所作所为:

在Controller / Details / _PartialView文件中,我放置了一个锚标记:

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

当呈现Controller / Details时,显然会呈现_PartialView文件。

在Controller / Index中我有一个ActionLink,如下所示

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

当我在Chrome中检查呈现的HTML时,上面的链接不是我想要的,这是:

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

自从原帖以来,我是否误解了某些内容或更改了用法。我正在使用MVC 5 ASP.NET 4.5。

此致 克雷格

3 个答案:

答案 0 :(得分:3)

这是因为您告诉浏览器滚动到 ID anchor-point的元素,但您发布的元素只设置了< strong>名称属性。试试这个:

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

答案 1 :(得分:2)

以下是ASP.NET MVC 5 ActionLink到Home控制器的示例,带有锚标记“whatis”的索引视图

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

没有图标就是

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

这是a link一个博客,可以很好地解释这一切。

答案 2 :(得分:0)

<ul>
     @foreach (var item in Model)
     {
     <li>                                   
     <a href='@Url.Action("Login",new{id=item.id})'>@item.post_name</a>
      </li>
       }
  </ul>
相关问题