Click here to Skip to main content
15,885,004 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to get data from two table or two class in single view in mvc3.
I want to show data from both the table. I have one parent class and two child class.
i.e
C#
public class GetDocumentParent 
{ 
public DOCUMENTS getDocument { get; set; } 
public DOCUMENT_REVISIONS getDocumentRevision { get; set; }
 }

Thanks in advance
Posted
Updated 27-Aug-12 1:22am
v2

1 solution

You should create a viewmodel, which is a class that has all the data you need, and pass that to your view. This is a layer between your model classes, and the collection of data needed by a page. You can only pass one model in, so you need to create one class that has all the data you need.

In addition, if you're using EF and writing code to map to an existing DB ( rather than auto generating code from the DB ), you can extend your DB model classes so that your DOCUMENTS class can have a property that returns all the DOCUMENT_REVISIONS for the selected document. I do this, we have a top level class, and once I have an instance of that in my viewmodel, it has properties I can use to get all related collections that exist in the DB. It's very neat and clean.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900