views:

993

answers:

1

I have a strongly typed master page, but I want to use a different type for some of it's child pages.

For example, on the master page...

<%@ Master ... Inherits="System.Web.Mvc.ViewMasterPage<MyWeb.Models.Client>" %>

Client is already a composite object, so on some of the child pages I can keep to the same model and just reference member objects. But on other pages, it won't make sense to do so as I am dealing with a different model, for example, a child page that deals with a Customer model.

My master page still needs the Client model, but the child views will work with different models entirely. The problem is, in a controller, there you can only pass one object model to the View. Is there any way to pass one model to the master and a different one to the view? Thanks!

+7  A: 

You can create an hierarchy and pass the base model to the master page and child models to your views.

public class BaseModel
{
}

public class ChildModelOne : BaseModel
{
}

public class ChildModelTwo : BaseModel
{
}

This way, you master view will only see its own data (available in master model class) while you views will have access to the extended information available in child model classes.

Very simple.

User