In my Asp.net MVC project an Index view contains a block in which you open the PartialViews Edit Details and Delete in a Modal window. Everything works 100%, but I'm having a problem with the Event of my "PersonNature" Combobox that is not working the Change event.
The combobox PersonNature is in the PartialView _Person and is rendered inside the PartialView Create. When I select a PersonNature, in the combobox, in thesis, one must give a POST for the Action to change some data and return again to the PartialView Create in Modal form, but this is not happening. The change event is not responding ... I tried to do it in other ways, but when it gave the post, it did not return the modal window and ended up opening the view on a new page ... What should I do? p>
MyJSFile:
$(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('');
});
$('#PessoaNatureza').on('change', function () {
openmodal(this.href);
return false;
});
});
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');
//Evento changed para poder alterar o tipo de pessoa
//$("#PessoaNatureza").change(function () {
// document.getElementById('frmCreate').submit();
//});
// 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;
}
});
}