gpt4 book ai didi

asp.net-mvc - 带有连字符的 ActionLink htmlAttributes

转载 作者:行者123 更新时间:2023-12-03 05:11:49 30 4
gpt4 key购买 nike

这有效

<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 中?

建议?

最佳答案

问题是您的匿名对象属性 data-icon 的名称无效。 C# 属性的名称中不能包含破折号。有两种方法可以解决这个问题:

使用下划线代替破折号(MVC 将在发出的 HTML 中自动将下划线替换为破折号):

@Html.ActionLink("Edit", "edit", "markets",
new { id = 1 },
new {@class="ui-btn-right", data_icon="gear"})

使用接受字典的重载:

@Html.ActionLink("Edit", "edit", "markets",
new { id = 1 },
new Dictionary<string, object> { { "class", "ui-btn-right" }, { "data-icon", "gear" } });

关于asp.net-mvc - 带有连字符的 ActionLink htmlAttributes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4108943/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com