39

I want to use "data-toggle" wiht actionLink. Like this;

 Html.ActionLink("Delete", "Users", "Admin", new { item.UserId , strRole = strRole }, new { id = "cmdDelete", href="#myAlert",  data-toggle="modal" })

Unfortunately, doesn't accept. How can i use "data-toggle" like standart links?

nermik
  • 1,485
  • 4
  • 16
  • 24

4 Answers4

87

You can't. But there is a simple work-around. What you do is, replace the - with a _. During runtime it will get converted to a dash (-). So;

Html.ActionLink("Delete", "Users", "Admin", new { item.UserId , strRole = strRole }, new { id = "cmdDelete", href="#myAlert",  data_toggle="modal" })
Nickvda
  • 1,585
  • 1
  • 16
  • 27
6
     @Html.ActionLink("TextLink", "ActionName", new { id = id }, new { @class = "btn btn-primary", data_toggle = "modal", data_target="#exampleModal" })
0

Add the action link simply as follows :

Html.ActionLink("Delete", "Users", "Admin", new { item.UserId , strRole = strRole }, new { id = "cmdDelete" })

then Use Jquery as follows :

$(document).ready(function () {
    $('#cmdDelete').attr('data-target', '#myAlert');
    $('#cmdDelete').attr('data-toggle', 'modal');
});
Dharman
  • 30,962
  • 25
  • 85
  • 135
BNG016
  • 164
  • 1
  • 7
0

Please replace data-toggle to data_toggle

Html.ActionLink("Delete", "Users", "Admin", new { item.UserId , strRole = strRole }, new { id = "cmdDelete", href="#myAlert",  data_toggle="modal" })
RainyTears
  • 171
  • 4