Jquery does not pass parameters to controller. The values are coming in blank.
Jquery:
function GravaEvento() {
var str = "";
var parametros = jQuery.parseJSON('{ "DE_Cnpj": "' + $("#txtCnpj").val() + '" , "DE_Descricao": "' + $("#txtDescricao").val() + '" , "DE_UsuProxAcao": "' + $("#txtUsuarioProxAcao").val()
+ '" , "DE_UsuProxAcao": "' + $("#txtProxAcao").val() + '" , "DT_ProxAcao": "' + $("#txtDataCadastro").val()
+ '" , "ID_TipoProxAcao": "' + $("#txtDataCadastro").val() + '" }');
$.ajax({
url: '/GerenciarPDV/GravaEvento',
datatype: 'json',
contentType: 'applicatio/json; charset=utf-8',
type: 'POST',
data: JSON.stringify({ _evento: parametros }),
success: function (data) {
},
error: function () {
}})
}
Controller
[HttpPost]
public JsonResult GravaEvento(T_CRM_Evento _evento)
{
V99_WEBEntities db = new V99_WEBEntities();
T_TecnicoExterno user = new T_TecnicoExterno();
user = (T_TecnicoExterno)SessaoUtil.Recuperar("sessionUser");
try
{
T_CRM_Evento evento = new T_CRM_Evento();
evento.DE_Cnpj = _evento.DE_Cnpj;
evento.DE_Descricao = _evento.DE_Descricao;
evento.DE_Usuario = user.DE_Login;
evento.DE_UsuProxAcao = _evento.DE_UsuProxAcao;
evento.DT_Inclusao = DateTime.Now;
evento.DT_ProxAcao = _evento.DT_ProxAcao;
evento.ID_TipoProxAcao = _evento.ID_TipoProxAcao;
db.T_CRM_Evento.Add(evento);
db.SaveChanges();
}
catch(Exception ex)
{
string erro = ex.Message;
}
return Json(new { }, JsonRequestBehavior.AllowGet);
}
The function calls the controller, but does not pass the values. T_TecnicoExterno
is a BD entity mapped by my Entity. I thought about creating an object with the same fields, but I thought it was repeating what already exists or not?
Jquery
function GravaEvento() {
var parametros = { _cnpj: $('#txtCnpj').val(), _descricao: $("#txtDescricao").val() };
$.ajax({
url: '/GerenciarPDV/GravaEvento',
datatype: 'json',
contentType: 'applicatio/json; charset=utf-8',
type: 'POST',
data: JSON.stringify(parametros),
success: function (data) {
},
error: function () {
}
})
}
Controller
[HttpPost]
public void GravaEvento(string _cnpj, string _descricao)
{
V99_WEBEntities db = new V99_WEBEntities();
try
{
T_CRM_Evento evento = new T_CRM_Evento();
evento.DE_Cnpj = _cnpj;
evento.DE_Descricao = _descricao;
db.T_CRM_Evento.Add(evento);
db.SaveChanges();
}
catch(Exception ex)
{
string erro = ex.Message;
}
}