My need is this: I write to a table, get the generated ID and write to the second table with that ID. As the order is to do this in jQuery, a function has been made (by a colleague). But unfortunately I can not write.
Notice that there are two calls in AJAX. If I remove the second step (persist in the second table), the code works. But when I enable the second code, nothing works, neither the 1st nor the 2nd calls. Below my jQuery code. If it were to do in Code Behind, I would know how to do it, because I already did a lot, but with jQuery I can not do it.
$(function () {
$("#btnGravarPassageiros").click(function () {
var result = {
Id: 0,
Nome: $("input[name ='txtNome']").val(),
CPF: $("input[name='txtCep']").val(),
Email: $("input[name='txtEmail']").val(),
DataNascimento: $("input[name='txtAno']").val() + "-" + $("input[name='txtMes']").val() + "-" + $("input[name='txtDia']").val(),
Telefone: $("input[name='txtTelefone']").val(),
Celular: $("input[name='txtCelular']").val(),
Endereco: $("input[name='txtLogradouro']").val(),
Numero: $("input[name='txtNumero']").val(),
CEP: $("input[name='txtCep']").val(),
Complmento: $("input[name='txtComplemento']").val()
};
var result = [];
var resultado;
var cont = 0;
$.ajax({
url: '/Passo/addCliente',
dataType: "json",
contentType: "application/json; charset=utf-8",
type: "POST",
data: JSON.stringify({ _tb_clientes: result }),
success: function (data) {
alert(data.Result);
$(".passageiro").each(function () {
nm = "txtNomePassageiro" + cont;
dia = "txtDiaPassageiro" + cont;
mes = "txtMesPassagecontro" + cont;
ano = "txtAnoPassagecontro" + cont;
sexo = "txtSexo" + cont;
numpassaporte = "txtPassaporte" + cont;
diavalidade = "txtDiaVal" + cont;
mesvalidade = "txtMesVal" + cont;
anovalidade = "txtAnoVal" + cont;
paisemissao = "txtPaisEmissao" + cont;
resultado = jQuery.parseJSON(
'{"Id_Cliente" : "' + data.Result +'" , "Nome": "' + $("input[name =" + nm + "]").val() +
'", "PassaPorte": "' + $("input[name =" + numpassaporte + "]").val() +
'", "DataNascimento": "' + $("input[name =" + dia + "-" + mes + "-" + ano + "]").val() +
'", "Sexo": "' + $("input[name =" + sexo + "]").val() + '", "PassaPorteValidade": "' +
$("input[name =" + diavalidade + "-" + mesvalidade + "-" + anovalidade + "]").val() +
'", "PassaPortePais": "' + $("input[name =" + paisemissao + "]").val() + '" }');
result.push(resultado);
cont++;
});
$.ajax({
url: '/Passo/addClientePassageiro',
dataType: "json",
contentType: "application/json; charset=utf-8",
type: "POST",
data: JSON.stringify({ _tb_clientes: result }),
success: function (data) {},
error: function (error) {}
});
},
error: function (error) {}
});
});
});
Personally I realized the following, that the write function in my controller works, at least in the first phase (1st table), but in the BD it gets everything null
, as if it were recognizing the past parameters of CSHTML. This is happening.