Web API model binder doesn't work with HttpPostedFileBase?

前端 未结 2 812
时光说笑
时光说笑 2020-12-11 19:55

Testing out Web API for file uploading, have a simple view model like this:

public class TestModel {
    public string UserId {get;set;}
    public HttpPoste         


        
2条回答
  •  执念已碎
    2020-12-11 20:22

    You can either write a custom MediaTypeFormatter to facilitate your scenario or you can pull the data out of the request by hand using MultipartFormDataStreamProvider.FormData.AllKeys collection. This way you can post both the file(s) and additional fields in one request.

    A good tutorial by Mike Wasson is available here: http://www.asp.net/web-api/overview/working-with-http/sending-html-form-data,-part-2

提交回复
热议问题