Code
I can not send an array of javascript objects to the server. ModelBinder standard does not recognize the format.
On my server I have classes:
public class PessoaViewModel
{
[HiddenInput(DisplayValue = false)]
public int Id { get; set; }
public string Nome { get; set; }
public string Tipo { get; set; }
public string CPF { get; set; }
public ICollection<TelefoneViewModel> Telefones { get; set; }
public ICollection<EnderecoViewModel> Enderecos { get; set; }
public ICollection<EmailViewModel> Emails { get; set; }
public PessoaViewModel Conjuge { get; set; }
}
public class TelefoneViewModel
{
[HiddenInput(DisplayValue = false)]
public int Id { get; set; }
[AdditionalMetadata("class", "span2")]
[AdditionalMetadata("placeholder", "Tipo")]
public string Tipo { get; set; }
[DataType(DataType.PhoneNumber)]
[AdditionalMetadata("class", "span2")]
public string Numero { get; set; }
[HiddenInput(DisplayValue = false)]
public int Ordem { get; set; }
}
I'm not listing the rest of the class because it is not yet used in the code!
My javascript
$.ajax
url: $(form).attr("action")
type: "POST"
error: (err, errType, errMessage) ->
console.error a.statusText
cache: false
data: ko.mapping.toJS(@, ignoreFunctionsMapping)
success: (data, txtStatus) -> console.log "OK!!?? On server maybe not!"
Server result
Full image: https://i.sstatic.net/NeIm1.jpg
Question
As you can see, the post is being done and the values are correct.
But asp.net mvc does not fill correctly the Telefones object!
What am I doing wrong?
$("form").serialize()