Using "data-toggle" with Html.ActionLink
Asked Answered
A

4

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?

Amateurism answered 19/10, 2012 at 14:12 Comment(0)
S
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" })
Selene answered 28/1, 2013 at 14:48 Comment(2)
Yes :) MVC 3,5 at least.Selene
Brilliant, just what I needed.Bisson
M
6
     @Html.ActionLink("TextLink", "ActionName", new { id = id }, new { @class = "btn btn-primary", data_toggle = "modal", data_target="#exampleModal" })
Meaganmeager answered 28/7, 2017 at 18:11 Comment(0)
H
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');
});
Haploid answered 21/9, 2021 at 14:23 Comment(0)
C
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" })
Countryside answered 5/7, 2023 at 11:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.