带有连字符的 ActionLink htmlAttributes
这可行,
<a href="@Url.Action("edit", "markets", new { id = 1 })"
data-rel="dialog" data-transition="pop" data-icon="gear" class="ui-btn-right">Edit</a>
但这不行。为什么?
@Html.ActionLink("Edit", "edit", "markets", new { id = 1 }, new {@class="ui-btn-right", data-icon="gear"})
看来您无法将 data-icon="gear"
之类的内容传递到 htmlAttributes
中?
建议?
This works
<a href="@Url.Action("edit", "markets", new { id = 1 })"
data-rel="dialog" data-transition="pop" data-icon="gear" class="ui-btn-right">Edit</a>
But this doesn't. Why?
@Html.ActionLink("Edit", "edit", "markets", new { id = 1 }, new {@class="ui-btn-right", data-icon="gear"})
It seems you can't pass something like data-icon="gear"
into htmlAttributes
?
Suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
问题是您的匿名对象属性
data-icon
的名称无效。 C# 属性的名称中不能包含破折号。有两种方法可以解决这个问题:使用下划线代替破折号(MVC 将在发出的 HTML 中自动将下划线替换为破折号):
使用接受字典的重载:
The problem is that your anonymous object property
data-icon
has an invalid name. C# properties cannot have dashes in their names. There are two ways you can get around that:Use an underscore instead of dash (MVC will automatically replace the underscore with a dash in the emitted HTML):
Use the overload that takes in a dictionary:
将所需的连字符替换为下划线;它将自动呈现为连字符:
变为:
Replace the desired hyphen with an underscore; it will automatically be rendered as a hyphen:
becomes: