Estoy tratando de hacer una acción de eliminación emergente con sweetalert2 en el proyecto central de asp.net
parece eliminar antes de que aparezca la ventana emergente
pero no funciona
JS:
jQueryAjaxDelete = form => { swal({ title: "Are you sure to delete this of ?", text: "Delete Confirmation?", type: "warning", showCancelButton: true, confirmButtonColor: "#DD6B55", confirmButtonText: "Delete", closeOnConfirm: false }, function () { $.ajax({ type: 'POST', url: form.action, data: new FormData(form), contentType: false, processData: false, success: function (res) { $('#view-all').html(res.html); }, error: function (err) { console.log(err) } }) } ) };en vista
<form asp-action="Delete" asp-route-id="@item.Id" onsubmit="return jQueryAjaxDelete(this)" class="d-inline"> <input type="hidden" asp-for="@item.Id" /> <input type="submit" value="Supprimer" class="btn btn-danger" /> </form>Necesita manejar el resultado de una promesa, como esta:
jQueryAjaxDelete = form => { swal({ title: "Are you sure to delete this of ?", text: "Delete Confirmation?", type: "warning", showCancelButton: true, confirmButtonColor: "#DD6B55", confirmButtonText: "Delete", closeOnConfirm: false }).then(value) => { // also be aware you need to check the "value" variable // to see if the user answered YES $.ajax({ type: 'POST', url: form.action, data: new FormData(form), contentType: false, processData: false, success: function (res) { $('#view-all').html(res.html); }, error: function (err) { console.log(err) } }); };