3

I have the following ViewModel and i would like to create a custom binder to bind subclasses (LogOnModel, ChangePasswordModel).

public class LogOnViewModel
{
    public string NextStep { get; set; }
    public string PreviousStep { get; set; }
    public string ReturnUrl { get; set; }
    public bool MustChangePassword { get; set; }
    public bool MustAgreeNewPrivacyStatement { get; set; }
    public LogOnModel logOnModel { get; set; }
    public ChangePasswordModel changePasswordModel { get; set; }
}

I was able to create my custom binder (inherit from DefaultModelBinder) but never was able to get a full VALIDATED model (ModelState populated) back into my controller. It's working fine for simple type (string, bool, ....) but a bit more complicated with complex type (subclass).

Is MVC 3 Futures the answer to my question or someone was able to override DefaultModelbinder to bind subclasses?

Thanks, Michel

tereško
  • 58,060
  • 25
  • 98
  • 150

1 Answers1

0

You will have to create custom model binders for LogOnModel and ChangePasswordModel as well; your custom model binder doesn't know automatically how to bind your complex types.

Sergi Papaseit
  • 15,999
  • 16
  • 67
  • 101