I have a page that is made up of many user controls. The view model for this page is rather complex.
public class ComplexViewModel
{
public ObjectA ObjectAProperty { get; set; }
public List<Things> ListOfThings { get; set; }
public List<ThingCategories> ListOfThingCategories { get; set; }
public List<ThingTypes> ListOfThingTypes { get; set; }
public List<ThingOptions> ListOfThingOptions { get; set; }
public int ChosenThingCategoryId { get; set; }
public int ChosenThingTypeId { get; set; }
public int ChosenThingOptionId { get; set; }
public OtherObject ObjectData { get; set; }
}
This page also has an PostModel that contains information for filtering, sorting, etc.
public class SimplePostModel
{
public int ChosenThingCategoryId { get; set; }
public int ChosenThingTypeId { get; set; }
public int ChosenThingOptionId { get; set; }
public int ChosenThingFilterTypeId { get; set; }
public int ChosenThingSortTypeId { get; set; }
public int ChosenThingOtherId { get; set; }
public int ChosenThingMoreId { get; set; }
public int ChosenThingOMGId { get; set; }
}
The simple PostModel is validated and then the controller opens 3+ repositories making multiple calls into each and builds the view model. To say the least my controller action has gotten quite large.
This is by far the most complex page I've worked on and I'm having a hard time deciding how to make it simpler.
My first thought was to create a view model factory that, after binding validation, would call into the repositories and return the ViewModel.
Then I thought about creating a custom model binder that would validate the PostModel and then hydrate the ViewModel in one step.
So my question is how do you hydrate a complex view model?
And while I write this I had the idea of using Html.RenderAction and creating a model for each of the user controls that make up this beast of a page.
Update:
The repositories make calls into WCF services, the application is part of a larger SOA arch.