Browse asp.net mvc with a homepage binding to various models

if I have a main page that links to ObjectA, and then a View that links to ObjectB, how it works (or even works) in asp.net mvc.

The main page may have:

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

and one of the types may have:

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

what would you switch to the view from the controller, since in this case you are using 2 models?

Is this bad practice that the main page has an anchor object?

+2
asp.net-mvc binding
source share
1 answer

Well, you can define an abstract container containing ObjectA:

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

and then all your views are inherited from this class and add their own data:

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

Then the main page can access the ObjectA property of the model, while individual views can ignore this particular property and access the data that they themselves need.

I can’t say that I especially like this approach. If I could avoid the need for a model on the main page, I would prefer that.

+3
source share

All Articles