本文介绍了无效的匿名类型成员声明。匿名类型成员必须与成员分配,简单名称或成员访问声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图附加属性的数据图标添加到我的操作链接,但我发现了以下错误:
Works:
@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" })
解决方案
UPDATE: From Xander's comment above, use data_icon = "gear"
You can use an IDictionary<string, object>
in place of the anonymous object for HTML attributes:
@Html.ActionLink("Profile", "Details", "Profile", new { id = 11 }
, new Dictionary<string, object>
{
{ "rel", "external" },
{ "id", "btnProfile" },
{ "data-icon", "gear" },
})
See this overload: http://msdn.microsoft.com/en-us/library/dd504988.aspx
The helper you are using is just a convenient method of creating the dictionary, but behind the scenes the dictionary is created anyway.
这篇关于无效的匿名类型成员声明。匿名类型成员必须与成员分配,简单名称或成员访问声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!