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?

4 Answers 4

88

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

2 Comments

Yes :) MVC 3,5 at least.
Brilliant, just what I needed.
6
     @Html.ActionLink("TextLink", "ActionName", new { id = id }, new { @class = "btn btn-primary", data_toggle = "modal", data_target="#exampleModal" })

Comments

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');
});

Comments

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" })

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.