I will need to check the ASP.NET MVC code (DefaultModelBinder), but I assume that it reflects the IProfile type, not the StandardProfile instance.
Thus, he is looking for all the members of the IProfile that he can try to link, but his interface is empty, so he believes that this is done.
You can try something like updating the BindingContext and change ModelType to StandardProfile and then call
bindingContext.ModelType = typeof(StandardProfile); IProfile profile = base.BindModel(controllerContext, bindingContext);
Anyway, having an empty interface is weird ~
Edit: I just want to add that the code above is just a pseudo code, you will need to check DefaultModelBinder to see what exactly you want to write.
Edit # 2:
You can:
public class ProfileModelBinder : DefaultModelBinder { public override object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext) { { bindingContext.ModelType = typeof(StandardProfile); return base.BindModel(controllerContext, bindingContext); } }
No need to create model bindings for AccountView, this works great.
Edit # 3
Tested, the binder described above works, just add:
ModelBinders.Binders[typeof(IProfile)] = new ProfileModelBinder();
Your action looks like this:
public ActionResult AddAccount(AccountViewModel viewModel) {
You can use IOC when setting up a model binding object (for example, an injected type constructor).
anonymous
source share