Modal bootstrap window does not open a partialview when deleting from the second page of a datatable

0

I have a modal window in my Index view that opens my PartialViews Create, Edit, and Delete. I have a datatable that contains pages ... Everything works normally if I delete records only from Page 1. If I try to Edit or Delete some record from page 2 onwards, Modal does not open the partialviews inside it ... Why does this occur and how can I solve this problem?

Thank you:)

 <a asp-action="Delete" asp-route-id="@item.Id" data-modal="" title="Excluir" class="btn btn-sm btn-icon btn-pure btn-default on-default">
                                <span class="icon-2x wb-trash"></span>
                            </a>

<div class="modal fade modal-primary" id="modalPessoa" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" data-backdrop="static">
    <div class="modal-dialog" style="width: 65%; height: auto;">
        <div class="modal-content ">
            <div id="contentModal"></div>
        </div>
    </div>
</div>

This is my JavaScript conf config file:

$(document).ready(function () {
    $.ajaxSetup({ cache: false });
    // busca los elementos el atributo data-modal y le suscribe el evento click
    $('a[data-modal]').on('click', function (e) {
        // Abre la ventana modal con el formulario solicitado 
        openmodal(this.href);
        return false;
    });
    $('#modalPessoa').on('hidden.bs.modal', function () {
        $('#contentModal').html('');
    })
});
function openmodal(url) {
    // Hace una petición get y carga el formulario en la ventana modal
    $('#contentModal').load(url, function () {
        $('#modalPessoa').modal({
            keyboard: true
        }, 'show');     
        // Suscribe el evento submit
        bindForm(this);
    });
}
function bindForm(dialog) {
    // Suscribe el formulario en la ventana modal con el evento submit
    $('form', dialog).submit(function () {
        if ($(this).valid()) {
            // Realiza una petición ajax
            $.ajax({
                url: this.action,
                type: this.method,
                data: $(this).serialize(),
                success: function (result) {
                    // Si la petición es satisfactoria, se recarga la página actual
                    if (result.success) {
                        window.location = window.location;
                        window.location.reload(); //Ajuda na exclusao, atualizando o grid

                    } else {
                        $('#contentModal').html(result);
                        bindForm();
                    }
                }
            });
            return false;
        } else {
            return false;
        }
    });
}
    
asked by anonymous 11.05.2018 / 23:47

0 answers