How to delete registry with modal?

Asked

Viewed 284 times

0

I have been dealing with ASP.NET for some time and I have come across a problem that I cannot solve. The idea is only to 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 believe 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);

  • I don’t quite understand the doubt. Your code is no longer working?

  • No, the idea is only to delete the record with id 4. The error occurs when I click on the delete confirmation "POST http://localhost:63712/Clients/Delete 500 (Internal Server Error)"

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.