2

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?

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.