我有一个 Ajax 调用,它将对象列表发送到控制器中的方法。
我查看了它发送的 json,一切似乎都井井有条。但是当它到达控制器时,列表就在那里,具有正确数量的对象,但它们的所有属性都是空的,即使值在 json 中正确设置。
示例:我有一个包含 10 个对象的列表,所有对象的属性都设置了特定值。我执行了调用,但是当列表到达控制器时,它有 10 个对象,它们的所有属性都设置为空。
有人知道为什么会这样吗?
这是电话:
由于大量数据,我不得不使用 post 而不是 get。
$("#testeFA").click(function()
{
<% JavaScriptSerializer serializador = new JavaScriptSerializer(); %>
var models = <%: MvcHtmlString.Create(serializador.Serialize(apontamentos)) %>
//"apontamentos" is the name of the List<ApontamentoModel>
$.post('<%: Url.Action("GeraFA") %>', { models: models }, function (sucesso)
{
//do whatever
}, 'json');
});
这是方法:
public JsonResult GeraFA(List<ApontamentoModel> models) <- this is where the list shows all the objects' properties as null
{
JsonResult result = new JsonResult();
//do whatever
result.JsonRequestBehavior = JsonRequestBehavior.AllowGet;
return result;
}
这是json的一部分,所以你可以看到结构:
[{"DocEntry":1,
"LineID":5,
"Data":"01/06/2012",
"HoraInicial":
{"Ticks":288000000000,
"Days":0,
"Hours":8,
"Milliseconds":0,
"Minutes":0,
"Seconds":0,
"TotalDays":0.33333333333333331,
"TotalHours":8,
"TotalMilliseconds":28800000,
"TotalMinutes":480,
"TotalSeconds":28800},
"CodigoCliente":"C00013",
"Cliente":"Client Name",
"CodigoProjeto":283,
"Projeto":"Project Name",
"CodigoServico":18,
"TipoServico":"",
"CodigoDespesa":0,
"Despesa":"",
"Quantidade":0,
"NumeroChamado":0,
"NumeroFA":10,
"Apropria":true,
"Narrativa":"teste",
"NomeConsultor":"Name"},
{"DocEntry":1,
"LineID":13 //and so on to all the other elements
我正在使用 MVC2