1
I have a strongly typed View with a small form and a javascript function with ajax:
function emitir () {
$.ajax({
type: "POST",
traditional: true,
url: '@Url.Action("EmissaoRapida", "CND")',
data: { model: @Model },
success: function (data) {
alert(data.mensagem);
},
error: function () {
alert("Erro na tentativa de emissão!");
}
});
}
I simply want to send my data model to my controller, the method that will receive the model has the following signature: public Jsonresult Emissaorapida (Emissaocnd model)
However some error happens, using the Firefox debugger I realized that there is something wrong at the time of the change of the model, because the problem is that the project root is not read as when I type in the view. @model Pro_certidao.Areas.Usuarios.Models.Emissaocnd
In error Pro_certidao is of a different color, I believe the problem is there and the message I fear is this: Javascript runtime error: 'Pro_certidao' is not set
Is there any way to fix this or do something similar by sending the complete data model?
The error no longer happens, at least the browser does not complain, but when it arrives in the method of my controller the model is null.
– Jefferson Pedro
check if your controller method is annotated with
[HttpPost]
and if your model is with[Serializable]
, ofSystem.SerializableAttribute
– Marllon Nasser
In the controller it was all right already, but in the Model I added the '[Serializable]' and nothing yet, but I can’t put the 'using' correct, in fact it doesn’t even let me add the 'System.Serializableattribute'
– Jefferson Pedro
I edited the reply post, gives a check as your model should be.
– Marllon Nasser
It’s pretty much the same, both Model and Controller. Only thing different is that I am using EF and use Dataannotation.Schema to better relate things to the database
– Jefferson Pedro
changed the method
emitir()
, take a look..– Marllon Nasser