3
I made a function in the model and the call in the controller. Then, I go to jquery and the write command in the BD is successfully executed. It turns out, when I finish recording, the screen continues with the previous information, i.e., the completed textbox, the checkbox’s checked. How do I make it after recording in the BD (ajax hit) I reload the page or the changed fields only? Below my jquery call. The alert with the message can be disregarded if necessary.
var checkedItemsUn = {}, checkedItemsMot = {}, checkedItemsPdv = {}, counter = 0;
function Gravar() {
$("#check-list-box li.active").each(function (idx, li) {
checkedItemsUn[counter] = $(li).text();
counter++;
});
counter = 0
$("#check-list-box-mot li.active").each(function (idx, li) {
checkedItemsMot[counter] = $(li).text();
counter++;
});
counter = 0
$("#check-list-tipo li.active").each(function (idx, li) {
checkedItemsPdv[counter] = $(li).text();
counter++;
});
counter = 0
str = "";
$.ajax({
url: '/CadastroCargo/GravaResponsavel',
datatype: 'json',
contentType: 'application/json;charset=utf-8',
type: 'POST',
data: JSON.stringify({ _responsavel: $('#txtResponsavel').val(), _ativo: $('#ckbAtivo').prop("checked"), _Un: checkedItemsUn,
_motivo: checkedItemsMot, _pdv: checkedItemsPdv, _nivel: $('#cbxNivelResp').val()
}),
success: function (data) {
str += '<div class="alert alert-success col-md-6">';
str += '<button type="button" class="close" data-dismiss="alert"></button>';
str += '<h4>Operação realizada com sucesso!</h4>';
str += 'Registro gravado no banco de dados com sucesso.';
str += '</div>';
$('#alerta').html(str);
str = "";
},
error: function (error) {
}
})
}
If you do
window.location.href = "/oTeuController/aTuaFuncao"
and upload the data to the controller and send to the view...– CesarMiguel
Should I set my function or Action? I set the action and it didn’t work. What function? Because all have parameters and are for the functionality of the page, I do not understand.
– pnet
At the end of recording the data, in the Success you make a
windows.location.href
to a function that will load the data into a view. The parameters to be set is your controller first and then your function...– CesarMiguel
I made: window.location.href = '/Register/Register position'; Where Register is my controller and my Action and it worked.
– pnet