asp.net-mvc - MVC ActionLink html 属性

标签 asp.net-mvc asp.net-mvc-4 actionlink

我想使用 ActionLink 而不是纯 html 来弹出我的模式窗口,但它可以在纯 html 标签上正常工作,但不能在 MVC actionlink 上正常工作,请看下面。

来自:(工作中)

<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" })

关于asp.net-mvc - MVC ActionLink html 属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31197956/

相关文章:

ASP.NET MVC - 对象引用未设置为对象的实例

c# - 是否可以使用包含元素的 ActionLink?

jquery - 带有 id 属性的 Ajax.Actionlink 输出

asp.net-mvc - 读取 RedirectToRouteResult 的 RouteValues 字典

c# - 在 asp .net mvc 中,应如何布置发送以查看有关本地化文本的数据?

c# - 在 View 中找不到命名空间,在 Controller 中工作

asp.net-mvc - 坚持使用 ASP.NET MVC4 中的 Google API YouTube 搜索示例?

C# 不四舍五入

asp.net-mvc - MVC Ajax 与 Ajax.ActionLink

asp.net - ASP.NET/ASP.NET MVC中类似SSI的功能