I have model like this:
public class Model
{
[MaxLength(500)]
public string UserEmail { get; set; }
[Required]
[MaxLength(100)]
public string Product { get; set; }
// ... And other 10 parameters
public byte[] StatisticsData { get; set; }
public byte[] UserXmlFile { get; set; }
}
Api should get some statistics information with binary data from clients with multipart/formdata. There are several similar methods with different models, so:
- I don't want to write custom MediaTypeFormatter for each model
- I want to keep standart Binding Model to simple fields, because of validation and easy binding
- We have an api help generator like this . So it's bad to parse the request in the controller in every situation.
Want to bind in mvc style :)
[HttpPost]
public HttpResponseMessage SiteMark(Model model)
{
I read this solution Web API model binder doesn't work with HttpPostedFileBase?, but it seems not very suitable for my situation and doesn't solve the problem of simple fields bindings.
I think about writing custom ModelBinder that uses standart binding for simple fields. Even we can use default mvc binder for this (webapi default binding seems to be unreusable in own code). And then Read all binary data in the cycle by custom code and map it to binary fields.
Maybe I'm missing something and there is a simpler solution?