Modal to delete Registry (.net core - javascript - Bootstrap)

Asked

Viewed 383 times

1

I’m trying to use modal to delete a record from a table. By clicking on the delete button, I wanted to display a modal asking for confirmation for exclusion, so far so good, I was able to do, but go ahead that I am stuck. Follows my code.

button code of the page where the table is.

<button href="#" class="btn btn-danger btn-circle btn-sm" data-toggle="modal" data-target="#excluirmodal" onclick="Excluir(@item.idclientes)">Excluir</button>

modal code that is called.

<div class="modal fade" id="excluirmodal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <input id="idcliente" />
                    <div class="modal-body">Deseja realmente excluir?<span id="idcliente"></span></div>
                    <div class="modal-footer">
                        <button class="btn btn-secondary" type="button" data-dismiss="modal">Cancelar</button>
                        <a class="btn btn-primary" href="../home/login/0">Sim</a>
                    </div>
                </div>
            </div>
        </div>

And this is my javascript Function

function Excluir(idclientes) {
        document.getElementById('idcliente').value = idclientes;

    }

This is the result. The text box is for test only, to see if you are receiving table ID.

esse é o resultado

Now I am not able to delete the record when I click on "yes", I do not know how to do this function.

1 answer

0


How did you not give as much information as the name of controller and details of view, I’ll use a few examples assuming what you might be using.

Put a ID on your confirmation button modal:

<a id="btnConfirmarModal" class="btn btn-primary" href="../home/login/0">Sim</a>

Assuming you’re using a form in your HTML with the name Meuform, you can do this:

$('#btnConfirmarModal').click(function () {
    $('#MeuForm').submit();
});

If not, you can just send the ID that will be excluded for your controller, thus:

$('#btnConfirmarModal').click(function () {
    var id = $('#idcliente').val();
    $.post( '@Url.Action("Excluir", "Cliente")', { idcliente: id } );
});
  • this command is jQuery?

  • @Andréluizdasilva whenever see the $ symbol is Jquery

  • got it, I’m using the visual studio programming on . net core, to use jquery I would have to install the jquery nuget in my project would you tell me?

  • @Andréluizdasilva, just right click on the folder where you want to install / Add / Client-Side Library

  • To use jquery I have to put between <script> jquery </script code>?

  • Yes @Andréluizdasilva as it is also js code

  • Thanks, it worked out.

Show 2 more comments

Browser other questions tagged

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