Action接收我的对象,但所有属性都为null

时间:2014-09-01 13:21:08

标签: jquery asp.net-mvc post null

我正在尝试通过jquery post将对象发送到asp.net MVC 4中的一个动作 但每次我发送它,在动作中我只收到对象,但所有属性都为空。

请注意,如果我在子数组中发送2个itens,则在服务器中该对象在数组中有2个对象,但同样,所有属性都为null。

我的javascript:

    var pacote = {
        contato: obj,
        listaTelefones: telefones,
        listaEmails: emails
    };

    console.log(JSON.stringify(pacote));

    $.post(form.attr("action"), pacote, function (data) {
    });

THE CONSOLE.LOG RESULT:

{ 
            "contato" : { 
                "DataNascimento" : "11/04/1993",
                "Departamento" : "desenv",
                "IdCliente" : "2",
                "IdContato" : "",
                "Nome" : "jean",
                "Observacoes" : "testando",
                "Sobrenome" : "alves"
            },
            "listaEmails" : [ { 
                "Endereco" : "myemail@gmail.com",
                "Tipo" : "Tipo 2"
            } ],
            "listaTelefones" : [ { 
                "Numero" : "5185927878",
                "Tipo" : "Tipo 1"
            } ]
        }


MY ACTION:

        public ActionResult GravarContato(DTOContrato dtoContrato)
        {
        }

THE DTOContrato课程:

public class DTOContrato
{
    public Contato contato { get; set; }
    public List<Telefone> listaTelefones { get; set; }
    public List<Email> listaEmails { get; set; }

    public class Contato
    {
        public int IdContato { get; set; }
        public int IdCliente { get; set; }
        public string Nome { get; set; }
        public string Sobrenome { get; set; }
        public DateTime? DataNascimento { get; set; }
        public string Departamento { get; set; }
        public string Observacoes { get; set; }
    }

    public class Telefone
    {
        public string Tipo;
        public string Numero;
    }

    public class Email
    {
        public string Tipo;
        public string Endereco;
    }
}

谢谢大家

0 个答案:

没有答案
相关问题