tags:

views:

98

answers:

1

I'm just learning ASP.NET MVC and my first project is to create a simple link directory (like DMOZ).

I can easily build a strongly typed view of a list of subcategories for a category.

I can easily build a strongly typed view of a list of all the sites in a particular category.

Now, here's what I'm having trouble wrapping my head around:

If I'm viewing a particular category, how would I, in the same page view, display two models (sets) of data:

  1. Top of the page: All subcategories for the category being viewed.
  2. Bottom of the page: All sites in the category being viewed.

I don't have the faintest idea of how to return both the subcategory list and the site list to a particular view. Is it possible? Is there a clean way to do it? (Feel free to point me to an online tutorial or book chapter).

+1  A: 

There are two approaches: You can either store one list in ViewData and have it not be strongly typed in your view or you can create a separate ViewModel class which takes two or more existing models so you can refer to these models as properties of your strongly typed ViewModel class inside the View itself.

The best source of information I found was the sample chapter of the upcoming ASP.NET MVC 1.0 book. The first chapter was written by Scott Guthrie and can be found here: http://aspnetmvcbook.s3.amazonaws.com/aspnetmvc-nerdinner_v1.pdf

Lance Harper
Nice, it looks like the ViewData dictionary was exactly what I needed. Thank you.
Jason Champion