0
I have a routine to record in BD. With you in AJAX Success, fire a alert
, but does not save. A button that calls the method, passes the parameters to the method in the controller and that method saves, with a SaveChanges()
.
Note: Does not give any kind of error, but does not enter the method in controller. I put a break
right in the first key and does not enter, as if not calling. I put a Alert()
in the AJAX Success and I can fire.
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 was the technical field, was with the name changed and as it is required in BD, did not write. Interesting is not enter the catch. I used IE and was able to find out, q wasn’t getting it with Chrome. Now, the code is coming and not the dropdownlist text. step this _tecnico: $('#ddlTecnico'). val(), and the code is coming. will be because the value is the code and not text and I’m getting the val()?
is MVC or Web API?
– Fernando Leal
MVC. Use MVC with Jquery
– pnet
Have you tried testing your endpoint with Fiddler? Why it might be taking place "Multiple actions Were found that match the request". Code Error 500.
– Fernando Leal
The problem is that was the technical field, was with the name changed and as it is required in BD, did not write. Interesting is not enter the catch. I used IE and was able to find out, q wasn’t getting it with Chrome. Now, the code is coming and not the dropdownlist text. step this _tecnico: $('#ddlTecnico'). val(), and the code is coming. will be because the value is the code and not text and I’m getting the val()?
– pnet