. However, in the controller, I only get the Field id, and nothing from Answer , I can not see the problem. My array can get the data as it should, just not everything is passed to the controller.
JSON
var urlResposta = '@Url.Action("Create", "Resultado")';
var dtoEnvio = new Array();
$('.resposta').each(function () {
var obj = {
Resposta: {
Resp: $(this).find('.perg-resp').first().val()
},
Campo: { Id: $(this).find('#hidID').first().val() }
};
dtoEnvio.push(obj);
});
console.log(dtoEnvio)
$.ajax({
type: "POST",
url: urlResposta,
cache: false,
data: JSON.stringify(dtoEnvio),
datatype: 'json',
contentType: "application/json; charset=utf-8",
success: function (result) {
}
})
};
C # class properties
public class Resposta
{
public virtual Int64 Id { get; set; }
public virtual String Resp { get; set; }
public virtual Campos Campo { get; set; }
public virtual Usuario Usuario { get; set; }
}
Controller
[HttpPost]
public JsonResult Create(List<Resposta> listResposta)
{
}