I have a routine to write to DB. I get in AJAX's success, shoot a alert
, but it does not record. A button that calls the method passes the parameters to the method in the controller and this method writes, with a SaveChanges()
.
Note: It does not give any type of error, but it does not enter the controller method. I put break
well in the first key and it does not enter, as if it had not called. I put a Alert()
in AJAX success and I get to shoot.
My button:
str += '<button id="btn_Confirmar" name="btn_Confirmar" onclick=" return GravaPainelPesquisa();">Confirmar</button>';
My jQuery:
function GravaPainelPesquisa() {
var parametros = {
_cnpj: $('#txtCnpjPesquisa').val().replace(/[^\d]+/g, ''),
_tecnico: $('#txtTecnicoObs').val(),
_obs: $('#txtObservacao').val()
}
$.ajax({
url: '/Pesquisa/GravaPainelPesquisa',
datatype: 'json',
contentType: "application/json; charset=utf-8",
type: "POST",
data: JSON.stringify(parametros),
success: function (data) {
alert('Testando hoje, 20/06/2014');
},
error: function (error) {
}
})
}
And my controller
[HttpPost]
public void GravaPainelPesquisa(string _cnpj, string _tecnico, string _obs)
{
using (V99_WEBEntities db = new V99_WEBEntities())
{
T_LogCadastroPDV logcadastro = new T_LogCadastroPDV();
DateTime _datacadastro = new DateTime();
DateTime? _datacontrole = new DateTime();
DateTime? _datatransacao = new DateTime();
var resultado_log = db.T_CRM_StatusPDV
.Join(db.T_PDV, t1 => t1.DE_Cnpj, t2 => _cnpj, (t1, t2) => new { t1, t2})
.Where(status => status.t1.DE_Cnpj == _cnpj)
.Select(i => new { i.t1.DT_ControleV, i.t1.DT_TransacaoV, i.t2.DataCadastro });
foreach (var dados in resultado_log)
{
_datacadastro = dados.DataCadastro;
_datacontrole = dados.DT_ControleV;
_datatransacao = dados.DT_TransacaoV;
}
try
{
logcadastro.DE_CnpjPDV = _cnpj;
logcadastro.DE_Tecnico = _tecnico;
logcadastro.DT_Cadastro = _datacadastro;
logcadastro.DT_Controle = _datacontrole;
logcadastro.DT_Transacao = _datatransacao;
logcadastro.DE_Obs = _obs;
db.T_LogCadastroPDV.Add(logcadastro);
db.SaveChanges();
}
catch (DbEntityValidationException ex)
{
string erro = ex.Message;
}
}
}
The problem is that it was the technical field, had the name changed and as it is required in the BD, it did not record. The interesting thing is it did not go into catch. I used IE and I discovered, what I was not getting with Chrome. Now, the code is coming, not the dropdownlist text. This is the same as: $ ('# ddlTecnico'). val (), and the code is coming. will it be because the value is the code and not the text and I'm getting the val ()?