Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: MVC3
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
public class GetDocumentParent 
{ 
public DOCUMENTS getDocument { get; set; } 
public DOCUMENT_REVISIONS getDocumentRevision { get; set; }
 }
Thanks in advance
Posted 27-Aug-12 2:19am
Edited 27-Aug-12 2:22am
v2

1 solution

Rate this: bad
good
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.
  Permalink  

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



Advertise | Privacy | Mobile
Web03 | 2.8.141220.1 | Last Updated 27 Aug 2012
Copyright © CodeProject, 1999-2014
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