我正在尝试添加附加的属性数据图标到我的Action Link,但是我收到以下错误:
Invalid anonymous type member declarator. Anonymous type members must
be declared with a member assignment,simple name or member access.
作品:
@Html.ActionLink("Profile","Details","Profile",new { id = 11 },new { @rel = "external",@id = "btnProfile" })
例外:
@Html.ActionLink("Profile",@id = "btnProfile",@data-icon = "gear" })
解决方法
更新:从Xander的评论上面,使用data_icon =“齿轮”
您可以使用IDictionary< string,object>代替HTML属性的匿名对象:
@Html.ActionLink("Profile",new Dictionary<string,object> { { "rel","external" },{ "id","btnProfile" },{ "data-icon","gear" },})
看到这个超载:http://msdn.microsoft.com/en-us/library/dd504988.aspx
您使用的帮助器只是一种方便的创建字典的方法,但幕后,字典创建无论如何。