Asp – How to Create Master-Details view using Asp.Net MVC framework

I have been evaluating Asp.Net MVC framework for past couple of weeks for our enterprise application. One thing what I am trying to achieve is Master-Details view. As it’s very clear that there is no viewstate and no postback. Now for instance, I am using Products, Customers, Orders and Order Details table from Northwind database and using Asp.Net MVC I want to create a Master – Details view. Basically I don’t want to have separate views(in other words pages) for Order and Order Details. The view should be comprised of Order and Order Details. How should I design my controller and view to achieve this functionality.

Thanks & Regards,
Burhanuddin Ghee Wala

Best Solution

You would want to write a domain-specific viewmodel class that combines all the data from a single Order and its OrderDetails (I'm assuming there's a 1->N relation on Order->OrderDetails, not familiar with Northwind):

public class OrderViewModel
  public Order Order {get;set;}
  public IEnumerable<OrderDetail> OrderDetails{get;set;}

Create a View template that binds to this type, rendering the order and the order details themselves on the same page.

In your controller class, write an action method that will populate a single instance of the OrderViewModel class and pass it to the View template.