4

I want to use ActionLink instead of plain html to popup my modal window but its working fine with plain html tag but not with MVC actionlink please have a look below.

from: (working)

<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">

to: (error)

@Html.ActionLink("Edit", "Edit", null, new { id = @item.Id }, new { @data-toggle="modal", @data-target="#myModal" })

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

Nick Kahn
  • 19,652
  • 91
  • 275
  • 406
  • 5
    You need to use the underscore character - `new { data_toggle="modal", data_target="#myModal" }` –  Jul 03 '15 at 03:31

2 Answers2

7

You need to use the underscore character instead or the hyphen character in the attribute name (the html helper will output the html correctly). Note also the @ character is not required (its only necessary when using a reserved word, e.g. class or readonly)

@Html.ActionLink("Edit", "Edit", null, new { id = @item.Id }, new { data_toggle="modal", data_target="#myModal" })
1
@Html.ActionLink("TextLink", "ActionName", new { id = item.Id }, new { @class="btn btn-primary", data_toggle="modal", data_target="#exampleModal" })