I'm trying to send an object to controller
, using ajax
.
The object goes to the controller with Json
, but only recognizes the values of the get, not the post.
$.ajax({
type: "POST",
url: "@Url.Action("AdiconarTeste", "Empresa")",
data: {empresa:JSON.stringify(@Html.Raw(Json.Encode(Model)))} ,
success: function (result) {
if (result.Success != false) {
if (result.Url != null) {
$(location).attr('href', result.Url);
} else {
divLista.html(result);
myModal.modal('hide');
}
} else {
alert(result.ErrorMessage);
}
}
});
});
The object arrives like this in the controller:
{
"empresaID":0,
"cidadeID":null,
"objCidade":null,
"nome":null,
"endereco":null,
"bairro":null,
"numero":null,
"cep":null,
"telefone":null,
"fax":null,
"url":null,
"listaTelefones[
{
"telefoneID":0,
"empresaID":null,
"ObjEmpresa":null,
"contatoID":null,
"objContato":null,
"tipo":3,
"numero":"69 3226 6565"
},
Obeservem that the list is populated, this is get of the controller that was done to populate it.
Model:
public class Empresa
{
public int empresaID { get; set; }
[Display(Name = "Cidade")]
public int? cidadeID { get; set; }
public string fax { get; set; }
[Display(Name = "URL"), DataType(DataType.Url, [ErrorMessage = "Url inválida")]
public string url { get; set; }
public virtual ICollection<Telefone> listaTelefones { get; set; }
public virtual ICollection<Teste> listaTestes { get; set; }
}