我正在尝试添加其他属性 数据图标到我的操作链接,但我收到以下错误:
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" })
异常(exception):
@Html.ActionLink("Profile", "Details", "Profile", new { id = 11 },
new { @rel = "external", @id = "btnProfile", @data-icon = "gear" })
最佳答案
更新:从上面 Xander 的评论中,使用 data_icon = "gear"
您可以使用 IDictionary<string, object>
代替 HTML 属性的匿名对象:
@Html.ActionLink("Profile", "Details", "Profile", new { id = 11 }
, new Dictionary<string, object>
{
{ "rel", "external" },
{ "id", "btnProfile" },
{ "data-icon", "gear" },
})
请参阅此重载:http://msdn.microsoft.com/en-us/library/dd504988.aspx
您使用的助手只是创建字典的一种方便方法,但无论如何在幕后创建了字典。
关于asp.net-mvc-3 - 匿名类型成员声明符无效。匿名类型成员必须使用成员赋值、简单名称或成员访问进行声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9196776/