5

请帮我在 api 帮助页面上添加一个 multipart/form 数据参数。

我正在使用Microsoft.AspNet.WebApi.HelpPage.VB 5.2.2

我想在 api 帮助页面上添加 CustomerName、fdStreet1、fdStreet2 参数信息。我怎样才能做到这一点?

这是我到目前为止所拥有的。

 <HttpPost> _
<ResponseType(GetType(TestModel))> _
<Route("TestAdd")> _
Public Function TestAdd() As IHttpActionResult

    Dim ServerUploadFolder = HttpContext.Current.Server.MapPath("~/Uploaded/")
    If Not Request.Content.IsMimeMultipartContent Then
        Throw New HttpResponseException(Request.CreateResponse(HttpStatusCode.UnsupportedMediaType))
    End If

    Dim streamProvider = New CustomMultipartFormDataStreamProvider(ServerUploadFolder)
    Request.Content.ReadAsMultipartAsync(streamProvider)

    'Read form data
    Dim _testModel As New TestModel
    _testModel.fdCustomerName = streamProvider.FormData("CustomerName")
    _testModel.fdStreet1 = streamProvider.FormData("fdStreet1")
    _testModel.fdStreet2 = streamProvider.FormData("fdStreet2")

    Return Json(_testModel)
4

0 回答 0