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?