Currently I've got this ModelBinder that works just fine:
public class FooModelBinder : IModelBinder
{
public bool BindModel(HttpActionContext actionContext, ModelBindingContext bindingContext)
{
var body = JObject.Parse(actionContext.Request.Content.ReadAsStringAsync().Result);
IEnumerable<Foo1> media = new List<Foo1>();
var transaction = body.ToObject<Foo2>();
media = body["Media"].ToObject<List<Foo3>>();
transaction.Media = media;
bindingContext.Model = transaction;
return true;
}
}
As you can see I'm mapping the whole bindingContext.Model, but what I really want to do is to map just the Media field of the Model and all of the other fields to map as default.
This is my controller:
public HttpResponseMessage Post([ModelBinder(typeof(FooModelBinder))] Foo request)
{
//do something
}
Is this achievable?
Here's how all of our model binders are defined:
public class FooBinder : IModelBinder {
If you want to make multiple parameters from your input you can just specify your desired binder in the your controller method.
I may have misunderstood your question but this is an example of real code in our system.