Registering attributes from different classes in the same View

Asked

Viewed 35 times

0

I have a Teacher class that has a User, and I want to register the User fields in the Teacher View.

How can I be doing this

public  class Usuario 
{ 
    public int Id { get; set; }

    public int Matricula { get; set; }

    public string Nome { get; set; }

    public string Email { get; set; }

    public DateTime DataCadastro { get; set; }

    public bool Ativo { get; set; }

}


public class Professor 
{
    public int Id { get; set; }

    public Usuario Usuario { get; set; }
}
  • There are several ways to solve this, but a tip is to watch the lesson of the link below. https://mva.microsoft.com/pt-br/training-courses/aspnet-mvc-intermedirio-12103?l=jZUi7sRIB_8004984382

1 answer

0


If the fields are within the same view, create the fields normally in the view by referencing the model object.

An Edit pro "Name" field of the "User" object in the Edit/Create view of the "Teacher" Controller would look like this:

@Html.EditorFor(model => model.Usuario.Nome) 

Browser other questions tagged

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