Non è facilmente possibile. Il binding del modello in Web API è fondamentalmente diverso rispetto a MVC e dovresti scrivere un MediaTypeFormatter che legge il flusso di file nel tuo modello e inoltre associa primitive che possono essere considerevolmente impegnative.
La soluzione più semplice è quella di afferrare il flusso di file fuori la richiesta utilizzando un certo tipo di MultipartStreamProvider
e gli altri parametri utilizzando FormData
nome valore di raccolta fuori quel provider
Esempio - http://www.asp.net/web-api/overview/working-with-http/sending-html-form-data,-part-2:
public async Task<HttpResponseMessage> PostFormData()
{
if (!Request.Content.IsMimeMultipartContent())
{
throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType);
}
string root = HttpContext.Current.Server.MapPath("~/App_Data");
var provider = new MultipartFormDataStreamProvider(root);
try
{
await Request.Content.ReadAsMultipartAsync(provider);
// Show all the key-value pairs.
foreach (var key in provider.FormData.AllKeys)
{
foreach (var val in provider.FormData.GetValues(key))
{
Trace.WriteLine(string.Format("{0}: {1}", key, val));
}
}
return Request.CreateResponse(HttpStatusCode.OK);
}
catch (System.Exception e)
{
return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, e);
}
}
fonte
2012-10-15 20:05:25
ok, grazie! e anche grazie per il tuo sito – user10479