Par6
Par6

Reputation: 389

asp.net MVC3 ActionResult multiple models and a view

What I am trying to do using asp.net MVC3:

-User selects a Category from a list of Categories.

-The SubCategories page then displays a list of images found to represent that Parent Category as well as the list of SubCategories.

I run into the need for multiple models because the "Category Images" are associated with Category and not the "SubCategory model". Yes I realize this seems like it has been asked many times before but the syntax is still foreign to a noob like me. What goes where?

I got the Category -> Html.Actionlink to the controller to return a list of SubCategories part... but even if I did some left join to get category and list of images as well, how would I get those into the same view as the list of subcategories?

Update Found this posting:

http://francorobles.wordpress.com/2011/05/03/returning-multiple-models-in-1-view-in-asp-net-mvc3/

Question: Is that a valid approach? My intellisense suggests no.

Upvotes: 0

Views: 922

Answers (1)

marcind
marcind

Reputation: 53183

In cases like this you need "view models", i.e. view-specific models that have all the data your view needs.

Upvotes: 1

Related Questions