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.

1
  • 5
    You need to use the underscore character - new { data_toggle="modal", data_target="#myModal" } Commented Jul 3, 2015 at 3:31

2 Answers 2

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" }) 
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.