1

I had a Model with a property that is an abstract class

public class MyModel
{
     public Foo Property { get; set; }
}

I have several implementations of Foo, each with their own EditorTemplate. Each implementation also has fields unique to it. Let's call these AFoo, BFoo, and CFoo.

Now, when I post my form, the model binder will try to create these all as Foo. Obviously, this will not work, because Foo is abstract.

Short of writing Model.GetType() to a hidden field, then using a custom model binder, is there a way to tell the default model binder how to correctly construct the correct type?

cadrell0
  • 17,109
  • 5
  • 51
  • 69
  • See http://stackoverflow.com/a/7222639/1625737 – haim770 Jul 10 '14 at 14:26
  • In addition to haim770 comment, take a look at http://stackoverflow.com/questions/9417888/mvc-3-model-binding-a-sub-type-abstract-class-or-interface – RyanCJI Jul 10 '14 at 14:30
  • @haim770 That's kinda what I was thinking when I said creating a custom model binder. I didn't know if there was any magic built in before I did that. – cadrell0 Jul 10 '14 at 15:10

0 Answers0