【问题标题】:@Html.ActionLink to a <a href="@Url.Action()>@Html.ActionLink 到 <a href="@Url.Action()>
【发布时间】:2018-01-20 10:11:21
【问题描述】:

怀疑是这样的: 我必须使用&lt;a&gt;&lt;/a&gt;,因为我在所有应用程序中使用的符号,我正在使用 ASP.NET MVC。所以,我有一个href="@Url.Actionclass="btn btn-primary",一个简单的按钮:

<a href="@Url.Action("Manage", "Account")" class="btn btn-primary text-right">
<span class="glyphicon glyphicon-circle-arrow-left" aria-hidden="true"></span> Administrar 
</a>

(这是我需要的结构示例)

但现在我必须转换它:

@Html.ActionLink(User.Identity.GetUserName(), "Manage", "Account",
routeValues: null, htmlAttributes: new { title = "Administrar" })

到那个结构。事实是,我不知道把routevaluesUser.Identity.GetUserName() 放在哪里。我不需要htmlAttributes 也不需要标题。

请帮助我,非常感谢。

【问题讨论】:

    标签: asp.net-mvc razor html.actionlink url.action


    【解决方案1】:

    对于标题,您只需简单地使用title="Administrar",因此当您将鼠标悬停在按钮/链接上时,它仍会在工具提示中显示Administrar

    对于用户名,您需要在前面签名@

    <a href="@Url.Action("Manage", "Account")" class="btn btn-primary text-right"
       title="Administrar">
      <i class="fa fa-arrow-circle-left" aria-hidden="true"></i> 
      @User.Identity.GetUserName()
    </a>
    

    另一个建议是不要使用 Bootstrap 的 glyphicon,因为它们将不再在 next version 中可用。相反,您可能需要考虑使用Font Awesome

    【讨论】:

      【解决方案2】:

      应该是:

      <a href="@Url.Action("Manage", "Account")" class="btn btn-primary text-right">
      <span class="glyphicon glyphicon-circle-arrow-left" aria-hidden="true"></span> 
         @User.Identity.GetUserName() 
      </a>
      

      routevalues 将是Url.Action 方法中的下一个参数,如果您需要的话。

      像这样:

      Url.Action("Manage", "Account", new { id = 1 })
      

      【讨论】:

        【解决方案3】:
        I suppose you have Html.Actionlink like bellow
          
        
             @Html.ActionLink("Home", "index", null, new  { @class = "btn btn-primary" })
        
        all you need to do is to write it like this 
        
            <a class="brand" href="@Url.Action("index","Home")"> </a>
        
        and you are done!
        

        【讨论】:

          猜你喜欢
          • 2014-07-30
          • 2012-02-23
          • 1970-01-01
          • 2021-03-15
          • 2011-12-04
          • 1970-01-01
          • 2011-02-06
          • 2021-08-19
          • 2015-07-27
          相关资源
          最近更新 更多