我需要在我使用
Html.ActionLink()构造的锚上放置一个自定义属性,
<%: Html.ActionLink("Delete","Delete",new { id = Model.ID },new { data-icon = "ui-icon-trash" })%>
使用正确的“data-”前缀,根据http://www.w3.org/TR/html5/elements.html#attr-data,我从Visual Studio中收到以下错误.
Invalid anonymous type member declarator. Anonymous type members must be declared with a member assignment,simple name or member access.
解决方法
数据图标不是有效的C#变量名称.最接近的是:
<%: Html.ActionLink( "Delete",new Dictionary<string,string> { { "data-icon","ui-icon-trash" } } ) %>
当然这个问题在ASP.NET MVC 3已经解决了,你不再需要写意大利面代码了.所以:
<%: Html.ActionLink( "Delete",new { data_icon,"ui-icon-trash" } ) %>
下划线将自动转换为连字符.