Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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" }) 
like image 266
Eugene Avatar asked Feb 08 '12 15:02

Eugene


2 Answers

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.

like image 139
Paul Tyng Avatar answered Jan 05 '23 16:01

Paul Tyng


I think you use underscore like data_icon and it translates it

like image 32
Richard Maxwell Avatar answered Jan 05 '23 16:01

Richard Maxwell