无效的匿名类型成员声明。匿名类型成员必须与成员分配,简单名称或成员访问声明 [英] Invalid anonymous type member declarator. Anonymous type members must be declared with a member assignment, simple name or member access

查看:773
本文介绍了无效的匿名类型成员声明。匿名类型成员必须与成员分配,简单名称或成员访问声明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图附加属性的数据图标添加到我的操作链接,但我发现了以下错误:


  

无效的匿名类型成员声明。匿名类型成员必须
  与成员分配,简单名称或成员访问声明。


作品:

  @ Html.ActionLink(档案,详细信息,档案,新{ID = 11},
            新{@rel =外部,@id =btnProfile})

例外:

  @ Html.ActionLink(档案,详细信息,档案,新{ID = 11},
            新{@rel =外部,@id =btnProfile,@数据图标=齿轮})


解决方案

更新:从Xander的评论上面,使用 data_icon =齿轮

您可以使用的IDictionary<字符串对象> 到位HTML匿名对象的属性:

  @ Html.ActionLink(档案,详细信息,档案,新{ID = 11}
    ,新的字典<字符串对象>
    {
        {相对,外部},
        {ID,btnProfile},
        {数据图标,齿轮},
    })

请参阅此重载:<一href=\"http://msdn.microsoft.com/en-us/library/dd504988.aspx\">http://msdn.microsoft.com/en-us/library/dd504988.aspx

您正在使用的辅助函数创建字典的一种简便方法,但幕后反正是创建的字典。

I'm trying to add additional attribute data-icon to my Action Link, but I'm getting the error below:

Invalid anonymous type member declarator. Anonymous type members must be declared with a member assignment, simple name or member access.

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.

这篇关于无效的匿名类型成员声明。匿名类型成员必须与成员分配,简单名称或成员访问声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆