Controller and View Structure

Asked

Viewed 208 times

1

A help not to do something much more laborious than it can be right away. I have the following classes in my Model:

public Pessoa {
    public int Id { get; set; }
    public int TipoPessoaId { get; set; }
    public string Nome { get; set; }
    public ICollection<Contato> Contatos { get; set; }
    public ICollection<Refencia> Referencias { get; set; }
    //...
} 

public Conjuge {
    public int Id { get; set; }
    public int PessoaId { get; set; }
    public string Nome { get; set; }
    public Pessoa Pessoa { get; set; }
    //...
}

public Contato {
    public int Id { get; set; }
    public int PessoaId { get; set; }
    public string Anotacao { get; set; }
    public string Numero { get; set; }
    public Pessoa Pessoa { get; set; }
    //...
}

public Referencia {
    public int Id { get; set; }
    public int PessoaId { get; set; }
    public string Nome { get; set; }
    public string Anotacao { get; set; }
    public Pessoa Pessoa { get; set; }
    //...
}

And the question is this: I need to assemble my view (single-page) as follows:

  • Campos de Pessoa
  • Campos de Conjuge
  • Person may have N Contacts
  • Add Contact Form for Person
  • Person may have N References
  • Form Add Reference to Person

But I don’t know the best or least problematic way to start view. But my biggest problem is controller.

Remembering that there are basic things to be taken into account as: contact can only exist if there is the person with id for him, the same is given the reference, and these two cases will be a list that can increase... and as in view assign that list to model?

In my action how would I do it? I mean, I want to know how the view which I think will get complex for the action. It would have to pass a FORM or has how to pass the Object?

  • Your question is a little confused. You can rephrase it nicely?

  • 1

    @Matheusbessa I reformulated

1 answer

2

If I were you, I would Scaffold of View static same. There’s a Nuget package that does that:

Install-Package Mvcscaffolding

After having the static View I would do it in Single Page.

To generate your Controller and Views, use the following command:

scaffold controller Pessoa

scaffold controller Conjuge

scaffold controller Contact

scaffold controller Reference

Having the Controllers moulded, the work of making Views becomes simpler.

Increment a question so I can increment my answer. Describe what you imagine for your Views (master-detail, Ajax, how will the transition between the screens, etc.).

Remembering that there are basic things to be taken into account as: contact can only exist if there is the person with id for it, the same is given the reference, and these two cases will be a list that can be incremented... and as in the view assign this list to model?

It seems to be a typical case of master-detail. For this case, there is another Nuget package that solves your problem: Mvcbegincollectionitem.

In my action like I would? I mean, I want to know how this view should be passed that I think will be complex for the action. It would have to pass a FORM or has how to pass the Object?

The ideal is to always pass the object that instantiates the class of the Model, which is the most natural way for the Entity Framework to work.

  • It would be yes Master-Detail to Contact and Reference

Browser other questions tagged

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