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

后端 未结 4 2188
青春惊慌失措
青春惊慌失措 2021-01-01 11:26

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

Invalid anonymous type member

4条回答
  •  爱一瞬间的悲伤
    2021-01-01 11:49

    UPDATE: From Xander's comment above, use data_icon = "gear"

    You can use an IDictionary in place of the anonymous object for HTML attributes:

    @Html.ActionLink("Profile", "Details", "Profile", new { id = 11 }
        , new Dictionary
        {
            { "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.

提交回复
热议问题