Related entity on page Razor

Asked

Viewed 39 times

1

I have a problem on a page Razor, I have a "Person" entity that has a relationship with the entity "Address"

public class Pessoa
{
public int Id {get; set;}
public string Nome {get; set;}
public virtual Endereco EnderecoPessoa {get; set;}
}

public class Endereco
{
public int Id {get; set;}
public string Logradouro {get; set;}
public int PessoaId {get; set;}
public Pessoa Pessoa {get; set;}
}

How do I set up on the Razor page to receive address data?

I’ve tried the following ways:

@Html.EditorFor(model => model.Endereco)

and also

<input asp-for="EnderecoPessoa.Logradouro" class="form-control" />

In either case, I receive the address data in the controller when I put the form.

How do I receive the data from the controller’s address ?

  • How is personal data passed to View? There’s probably a controller where you query and send the model to View, right? Put her.

  • is a registration, has not given being sent to the View, only from View to the controller. All data is received, except address data.

  • So put the view code, please.

1 answer

3

You must use the "complete path"

@Html.EditorFor(model => model.Endereco.Logradouro)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.