implementation of sweet alert in an @ html.ActionLink


I need my @Html.ActionLink(); to execute a onclick() and then I run the driver that I send as overload this is what I have.

@Html.ActionLink("Delete", "DeleteMunicipality", new { id = item.MunicipalityId }, new { @class = "btn btn-danger", onClick = "swal({   title: 'Are you sure?',   text: 'You will not be able to recover this imaginary file!',   type: 'warning',   showCancelButton: true,   confirmButtonColor: '#DD6B55',   confirmButtonText: 'Yes, delete it!',   closeOnConfirm: false }, function(){   swal('Deleted!', 'Your imaginary file has been deleted.', 'success');});" })'
asked by Kmiilo Berrio Montoya 10.06.2016 в 19:15

1 answer


If the ActionLink () makes a submit to the server what you have executed in the client, you would not have any validity, what I would recommend is that you work everything in client code.

You could define a simple link in html and assign jquery to perform the action

<a id="link1" valor="@item.MunicipalityId" >Delete</a>


           //aqui realizas la accion que necesites

           var params = {
              id: $(this).attr('valor');

             type: "POST",
             url: '@Url.Action("Delete", "DeleteMunicipality")',
             data: params,
             datatype: "html",
             success: function (data) {


The idea is that you execute the action you need in the client code and use jquery with $ .ajax invoke the action of the controller

Posting Data With jQuery AJAX In ASP.NET Razor Web Pages

jQuery Ajax GET and POST calls to Controller's Method in MVC

answered by 10.06.2016 / 21:05