加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc-3 – 无效的匿名类型成员声明符 必须使用成员分配,

发布时间:2020-12-16 00:45:52 所属栏目:asp.Net 来源:网络整理
导读:我正在尝试添加附加的属性数据图标到我的Action Link,但是我收到以下错误: Invalid anonymous type member declarator. Anonymous type members must be declared with a member assignment,simple name or member access. 作品: @Html.ActionLink("Profi
我正在尝试添加附加的属性数据图标到我的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

您使用的帮助器只是一种方便的创建字典的方法,但幕后,字典创建无论如何。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读