I made an ajax request, but it does not call the controller, when debugging javascript never drops in success and the console appears Error processing XML.
Controller:
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Cadastro(Pedido pedido)
{
if (ModelState.IsValid)
{
var appPedido = new PedidoAplicacao();
appPedido.Salvar(pedido);
return Json(new { Resultado = "Sucesso" });
}
return Json(new { Resultado = pedido }, JsonRequestBehavior.AllowGet);
}
View where I call the js function:
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<a href="#" id="SalvarPedido">Enviar</a>
</div>
</div>
Script
function SalvarPedido() {
var valor = $('#Valor').val();
var cadastro = $('#Data').val();
var url = "/Pedido/Cadastro";
$.ajax({
url: '/Pedidos/Cadastro' ,
type: "POST",
dataType: "json",
contentType: 'application/json; charset=utf-8',
data: { Id: 0, Data: cadastro, Valor: valor },
success: function (data) {
alert('Ok');
}
})
He does not even go to the controller. The following is the console image:
Errorcodegeneratedintheaboveimage:
ErrorprocessingXML:noelementfoundLocation: link