@ Html.ActionLink的奇怪行为

时间:2014-07-24 07:48:20

标签: razor

我正在Bootstrap布局中制作一个razor的菜单,但我遇到了一个简单@Html.ActionLink

的问题
<ul>
    <li class="dropdown-header">Editorial</li>
    <li><a role="menuitem" tabindex="-1" href="/Posts/">Posts</a></li>
    @*<li>@Html.ActionLink("Posts", "Index", "Posts",htmlAttributes: new { role = "menuitem", tabIndex = "-1" })</li>*@
    <li>@Html.ActionLink("Tags", "Index", "Tags", htmlAttributes: new { role = "menuitem", tabIndex = "-1" })</li>
    <li class="divider"></li>
    <li class="dropdown-header">Dropdowns</li>
    <li><a href="#">Example</a></li>
    <li><a href="#">Aligninment options</a></li>
    <li><a href="#">Headers</a></li>
    <li><a href="#">Disabled menu items</a></li>
</ul>

以下声明并不像我想要的那样工作

@Html.ActionLink("Tags", "Index", "Tags", htmlAttributes: new { role = "menuitem", tabIndex = "-1" })

这是我的渲染:

<li class="col-sm-3">
    <ul>
        <li class="dropdown-header">Editorial</li>
        <li><a role="menuitem" tabindex="-1" href="/Posts/">Posts</a></li>
        <li><a href="/?Length=4" role="menuitem" tabindex="-1">Tags</a></li>
        <li class="divider"></li>
        <li class="dropdown-header">Dropdowns</li>
        <li><a href="#">Example</a></li>
        <li><a href="#">Aligninment options</a></li>
        <li><a href="#">Headers</a></li>
        <li><a href="#">Disabled menu items</a></li>
    </ul>
</li>

为什么 @ Html.ActionLink(&#34;标签&#34;,&#34;索引&#34;,&#34;标签&#34;,htmlAttributes:new {role =&#34; menuitem& #34;,tabIndex =&#34; -1&#34;})<a href="/?Length=4" role="menuitem" tabindex="-1">Tags</a>呈现?

1 个答案:

答案 0 :(得分:0)

这可以解决问题。

@Html.ActionLink("Tags", "Index", "Tags", null, htmlAttributes: new { role = "menuitem", tabIndex = "-1" })