Controller and View Structure

1

An aid to not doing something much more laborious than it can be soon of face. 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 mount my view (single-page) as follows:

  • Person Fields
  • Spouse Fields
  • Person can have N Contacts
  • Form add Contact to Person
  • Person can have N References
  • Form add Reference for Person

But I do not know what the best or least problematic way to get the view. But my biggest problem is in controller .

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

In my action how would I do it? That is, I want to know how this view should be passed which I think will be complex for action . Should I pass a FORM or can I pass the Object?

    
asked by anonymous 31.03.2014 / 20:43

1 answer

2

In its place, I would do Scaffold from the static view. There is a NuGet package that does this:

  

Install-Package MvcScaffolding

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

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

  

scaffold controller Person

     

scaffold controller Spouse

     

scaffold controller Contact

     

scaffold controller Reference

Having the Controllers preformatted, the job of making the Views becomes simpler.

Ask me a question so that I can increase my answer. Describe what you envision for your Views (master-detail, Ajax, how to transition between screens, etc.).

  

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

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

  

In my action how would I do it? That is, I want to know how to pass this view that I think will be complex for the action. Should I pass a FORM or can I pass the Object?

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

    
31.03.2014 / 21:00