0

Previous versions of ASP.Net exposed the inheritable class System.Web.Mvc.DefaultModelBinder, which allowed the method CreateModel in order to return the type of model which the incoming request should bind to. It's very handy for having a single method for different base classes.

This doesn't exist in version 5. You can create Binders easily by inheriting from IModelBinder - in BindModelAsync the Model type can't be set. You can set the ModelMetadata.Model (which I believe would be an instantiation of the target type), but it's unclear how to set the Metadata itself which I think is needed.

Essentially I'm trying to ask this question for the newer framework.

Community
  • 1
  • 1
Party Ark
  • 1,061
  • 9
  • 20

1 Answers1

1

The question turns out to be based on a misconception. The WebAPI stack has never had a DefaultModelBinder, that's the MVC stack. There's so much naming overlap that's it's confusing which is which; that's something ASP.Net 5.0 is trying to overcome.

The answer to this question - how to bind to a model different to the one specified in the method parameters - involves using the Json.NET library. A good overview of two different techniques can be found in this answer.

This works perfectly well for ASP.Net 5.0 too.

Community
  • 1
  • 1
Party Ark
  • 1,061
  • 9
  • 20