5
I am studying Angularjs and Asp.net MVC and could not bind a property CPF class Person when performing a POST:
Classe Pessoa:
public class Pessoa
{
protected PessoaFisica() { }
public Int32 PessoaFisicaID{ get; set; }
public String Nome { get; set; }
public Cpf CPF { get; set; }
...
}
Class CPF:
public partial class Cpf
{
protected Cpf() { }
public Int64 Numero { get; private set; }
...
}
Controller Angularjs:
...
vm.salvar = function () {
var pessoaFisica = new Object();
pessoaFisica.PessoaFisicaID = vm.PessoaFisicaID;
pessoaFisica.Nome = vm.Nome;
//Bind do CPF com problema :-(
//Tentativa 1:
//pessoaFisica.CPF = new Object();
//pessoaFisica.CPF.Numero = vm.CPF;
//Tentativa 2:
pessoaFisica.CPF = vm.CPF;
//Uso o $http.post()
ajaxService
.ajaxPost(
pessoaFisica,
'/Home/Criar',
this.salvarPessoaFisicaOnSuccess,
this.salvarPessoaFisicaOnError
);
}
...
My Canvas:
At first try I used the code below, but it did not work:
//Tentativa 1:
pessoaFisica.CPF = new Object();
pessoaFisica.CPF.Numero = vm.CPF;
Error: System.Missingmethodexception: No constructor without parameters has been defined for this object.
In the second attempt I used the code below and also did not work:
//Tentativa 2:
pessoaFisica.CPF = vm.CPF;
Arrives null in Asp.net MVC controller:
What I might be adjusting to be able to make the CPF bind informed?
Tried to take the
private
ofset
of propertyNumero
in classCpf
?– Filipe Oliveira
I adjusted the code according to the @Randrade response, but it continued with the same error. System.Missingmethodexception: No constructor without parameters has been defined for this object. After a long time trying to find out ("thrashing") I identified that the error occurs because the CPF class has a constructor protected, I was able to perform the bind by changing the access to public. But will the solution is to put public access even?
– Renan