Asp.net-Mvc
ActionLink html屬性
作品
<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" } });