MVC ActionLink html attributes

I want to use ActionLink instead of normal html to pop up in my modal, but its working with normal html tag but not with MVC actionlink, please see 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. Members of anonymous type must be declared with member assignment, simple name, or member access.

+3


source to share


2 answers


Instead, you must use an underscore or hyphen in the attribute name (the html helper will render the html correctly). Note that the character is @

not required (it is only needed when using a reserved word like class

or readonly

)



@Html.ActionLink("Edit", "Edit", null, new { id = @item.Id }, new { data_toggle="modal", data_target="#myModal" })

      

+5


source


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

      



0


source







All Articles