MVC ActionLink html 属性

MVC ActionLink html attributes

我想使用 ActionLink 而不是普通的 html 来弹出我的模式 window 但它在普通的 html 标签上工作正常,但在 MVC 动作链接上不行,请看下面。

来自:(工作)

<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">

至:(错误)

@Html.ActionLink("Edit", "Edit", null, new { id = @item.Id }, new { @data-toggle="modal", @data-target="#myModal" })

Invalid anonymous type member declarator. Anonymous type members must be declared with a member assignment, simple name or member access.

您需要在属性名称中使用下划线字符或连字符(html 助手将正确输出 html)。另请注意 @ 字符不是必需的(仅在使用保留字时才需要,例如 classreadonly

@Html.ActionLink("Edit", "Edit", null, new { id = @item.Id }, new { data_toggle="modal", data_target="#myModal" })
@Html.ActionLink("TextLink", "ActionName", new { id = item.Id }, new { @class="btn btn-primary", data_toggle="modal", data_target="#exampleModal" })