Reputation: 3293
I have say class/ojbect one which I am returning as details. But then there is a second class that is related to the first that I want to list (and have an option to look at the details). How do I get return both of those?
Example is like in an item as the main piece but there may be details or other items that are related to the main item. I will select them with a linq query but then how do I return them to the same view?
Do I need to have some sort of partial or other form to display the second object type? I don't see where returning the view I can return both.
My thought for right now is to create a new class that contains both of the object types but I know there has to be a better way.
Upvotes: 0
Views: 342
Reputation: 1752
for the first object "main object" return it as the model of this view and for the details put them into ViewState and cast them back within the view
Upvotes: 0
Reputation: 46008
My thought for right now is to create a new class that contains both of the object types but I know there has to be a better way.
That is the right way. Create a ViewModel class that contains all the data that view needs and pass it to view.
Upvotes: 1
Reputation: 4400
You can either pass it to View through ViewState or ViewBag (depending on which MVC version you are using).
Upvotes: 1