作品
<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?
有什么建议吗?
发布于 2010-11-06 06:35:15
问题是您的匿名对象属性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" } });
发布于 2011-12-22 14:50:52
将所需的连字符替换为下划线;它将自动呈现为连字符:
@Html.ActionLink("Edit", "edit", "markets",
new { id = 1 },
new {@class="ui-btn-right", data_icon="gear"})
变成:
<form action="markets/Edit/1" class="ui-btn-right" data-icon="gear" .../>
发布于 2016-08-18 15:12:54
@Html.ActionLink("display name", "action", "Contorller"
new { id = 1 },Html Attribute=new {Attribute1="value"})
https://stackoverflow.com/questions/4108943
复制相似问题