How to delete registration with modal?

0

I've been tinkering with ASP.NET for some time, and I came across a problem I can not solve. The idea is to just open a modal window, click on the confirmation and delete a record. The idea of this code is for testing only, if I can make it work this way, I think I can adapt my code and do it in a smarter way.

I'll attach the codes. I'm using SweetAlert.

This is my Controller:

[HttpPost, ActionName("Delete")]
[ValidateAntiForgeryToken]
public ActionResult DeleteConfirmed(int id)
{
    _clienteApp.Remove(_clienteApp.GetById(id));
    return RedirectToAction("Index");
}

This is my delete button:

<button id="btn-deletar" data-codigo="@item.ClienteID"  class="btn btn-danger fa fa-trash fa-lg"></button>
<div id="dialog-confirm"></div>

This is my JS:

$(document).ready(function () {
function deleteDialog() {
    swal({
        title: "Tem certeza que deseja excluir o registro?",
        text: "Uma vez deletado, é impossível recuperá-lo",
        icon: "warning",
        buttons: true,
        dangerMode: true,
    }).then((willDelete) => {
        if (willDelete) {
            $.post("/Clientes/Delete/4");
            swal("Seu registro foi deletado!", {
                icon: "success"


            });
        } else {
            swal("Seu registro não foi deletado");
        }
    });
}
$('#btn-deletar').click(deleteDialog);
    
asked by anonymous 23.10.2017 / 14:37

0 answers