views:

305

answers:

1

if i have a master page that binds with ObjectA and then a View that binds with ObjectB, how does that work (or does it work at all) in asp.net mvc.

master page might have:

Inherits="System.Web.Mvc.ViewMasterPage<CalendarEvent[]>" %>

and one of the view might have:

Inherits="System.Web.Mvc.ViewPage<Tournament[]>" %>

what would you pass into the view from the controller since there are 2 models in this case you are binding to?

is this bad practice to have the master page have a binding object?

+3  A: 

Well, you could define an abstract container that contains ObjectA:

public class ModelContainer
{
    public ObjectA ObjectA { get; set; }
}

and then have all your views inherit from this class and add their own data:

public class SomeViewContainer : ModelContainer
{
    public ObjectB ObjectB { get; set; }
}

The master page can then access the ObjectA property of the model, while the individual views can ignore that particular property and access the data they themselves need.

I can't say I particularly like this approach, though. If there was any way I could avoid needing a model in the master page, I'd rather prefer that.

Mark Seemann