I've had a read through Jimmy Bogards post from a whiel back on how they do view models, in my own project I've come across a few places where there is quite a lot of information that needs to displayed at one time on the screen such as a form that needs to be filled out where all fields are shown at once.
So our view models would look something like
public class FormViewModel
{
public string field1 {get;set;}
public int field2 {get;set;}
public DateTime field3 {get;set;}
public string field4 {get;set;}
...snip
public string field50 {get;set;}
}
Now the forms do have sections so we could introduce a bit of structure into the viewmodels like this:
public class FormViewModelSection1
{
public string field1 {get;set;}
public int field2 {get;set;}
}
public class FormViewModelSection2
{
public DateTime field3 {get;set;}
public string field4 {get;set;}
}
and then the main viewmodel becomes
public class FormViewModel
{
public FormViewModelSection1 {get;set;}
public FormViewModelSection2 {get;set;}
}
so we would return the more complex viewmodel to a main view that basically just delegates each of its sections out to be rendered through a renderpartial like
<div>
My form
<%: Html.RenderPartial("soemascx", Model.FormViewModelSection1)%>
</div>
or maybe use an editorfor to render the contents.
My question is, is the "recomposing" of the viewmodel a valid thing to do or is it undoing some of the benefits that are provided by making a view model so flat.
I'd say there's no right answer to your question. It all up to usability and functionality. Maybe even personal coding style. Meaning as long is it is
consider it to be good solution. If you'd ask about what I'd do: I'd go with one flat class well decorated (data annotations) for names and validation, and structures supporting visual representation (like lists for combo boxes, enums (or whatever you comfortable with) for radio buttons.
As a note, I had some bad experience with hierarchies of view models (inheritance) - was working really poorly with validation (inherited data annotations don't work as expected with view model inheritance).
So to answer your specific question - no, you not doing anything wrong ... its up to you how to do it.
Hope this helps.