c# - how model use for display two tables in a view -


I want to display the elements of two tables in a scene but I do not know how.

In my opinion, I have a model einemareble which indicates the model's 'Tember' class and corresponds to the table 'Tmembre' in the database. I can display the elements in this table in my opinion, okay.

But I want to display elements of other tables in this scene and I can not waste other @models in the scene.

I try to create a class in the model for two tables and put the SQL in the model, but I think it is not in the model. I have to request DB.

  public class myviewmodel {public Tmembre tmembre {get; Set; } Public listing & lt; Tmembre & gt; GetlstMembre {// SQL} receive public content tassociation { Set; } Public listing & lt; TAociociation & gt; GetlstAssociation {// SQL}}  

You can create a new instance in your controller Fill out the above footage modell and members from your database and fill out the data.

Once you see it, you should return your ViewModel;

  Public Performance Index () {MyViewModel myViewModel = New MyViewModel (); MyViewModel.lstmembre = ....; MyViewModel.1stassociation = ...; See Return (myViewModel); }  

In your opinion, you can now designate the model @ as your visual model

  @model myproject.web.models.MyViewModel < / Code> 

All members of this model should now be available to access from your view

  Model.1stmembre Model.1stassociation Model.tmembre etc ..  

Comments

Popular posts from this blog

HTML/CSS - Automatically set height width from background image? -

php - Mysql Show Process - Sleep Commands and what to do -

c - What is the address of buf (the local variable in the main function)? -