【问题标题】:How Can I add a class to an HTML.ActionLink in MVC?如何在 MVC 中向 HTML.ActionLink 添加类?
【发布时间】:2017-06-09 01:52:32
【问题描述】:

我有下面发布的 html 代码。我想将该 Delete and Edit Button 类应用到 HTML Action Link。

这是我的代码。

@Html.ActionLink("Edit", "EditUser", new { UserName = item.UserName }) |
                        @if ((item.UserName.ToLower() != this.User.Identity.Name.ToLower()))
                            {
                            @Html.ActionLink("Delete", "DeleteUser", new { UserName = item.UserName },
                new { onclick = "return confirm('Are you sure you wish to delete this user?');" })
                        }

这个用于删除和编辑的 HTML 代码:

<a href="#" class="btn btn-info btn-xs black">
    <i class="fa fa-trash-o"></i> Delete
</a>
<a href="#" class="btn btn-success btn-xs purple">
    <i class="fa fa-edit"></i> Edit
</a>

我怎样才能让它工作?

我们将不胜感激。

【问题讨论】:

    标签: html twitter-bootstrap razor model-view-controller


    【解决方案1】:

    您必须使用 @ 字符,因为 class 是 C# 中的关键字。这是 MSDN 文档的链接:http://msdn.microsoft.com/en-us/library/dd492124(v=vs.108).aspx

    @Html.ActionLink("<i class='fa fa-trash-o'></i> Delete", "DeleteUser",
         new { UserName = item.UserName },
         new { @class = "btn btn-info btn-xs black" })
    

    【讨论】:

    • 它不工作。请查看更新后的问题
    猜你喜欢
    • 2013-12-23
    • 2013-09-09
    • 2020-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-10
    • 2015-07-27
    相关资源
    最近更新 更多