Click here to Skip to main content
13,259,194 members (50,661 online)
Rate this:
Please Sign up or sign in to vote.
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.
public class GetDocumentParent 
public DOCUMENTS getDocument { get; set; } 
public DOCUMENT_REVISIONS getDocumentRevision { get; set; }

Thanks in advance
Posted 27-Aug-12 2:19am
Updated 27-Aug-12 2:22am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web01 | 2.8.171114.1 | Last Updated 27 Aug 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100