Working with ViewModels, I would like to split them:
public SignUpViewModel //for display
{
public SignUpUserViewModel SignUpUserViewModel { get; set; } //for validation
public IEnumerable<SelectListItem> UserTypes {get;set;}
}
So I want to render SignUpViewModel but get SignUpUserViewModel as an argument of POST-action.
Do you find this reasonable? What are the ways to implement this approach?
Looks like DefaultModelBinder doesn’t work this way: it doens’t understand SignUpUserViewModel is a property of SignUpViewModel. So one way I see is to implement custom model binder. Any other?
I think that’s reasonable. Just have your post action bind to the
SignUpUserViewModel.E.g.
On a side note, looking at your
SignUpViewModelvsSignUpUserViewModel, I think you could just combine them into the one view model.In saying that I will say that I too sometimes have a similar setup to what you have, e.g.
ViewModeland a childFormModel(posting and binding to theFormModel) but I put anything to do with the form like validation and the SelectListItems in theFormModel. So in your case above, I would just combine them into the one FormModel.