我发现了一些相似的东西,但现在却很清楚如何做到这一点......我在采用我发现的情况时遇到了问题。我正在尝试将多个图像和文本传递给Web服务,然后保存到db / amazon。
这就是我到目前为止......
表格
<form class="create-status" enctype="multipart/form-data">
<div class="row">
<div class="col-sm-12">
@Html.TextAreaFor(model => model.status, new { cols = "1", rows = "1", @class = "form-control no-max-width input-sm", id = "tbStatus", placeholder = "Beep Here", req = "tbStatus" })
</div>
</div>
<div class="row collapse" id="divStatusInputs">
<br />
<div class="col-sm-6">
<div class="row">
<div class="col-sm-3">
<a class="icon"><span id="spanImageInput" class="glyphicon glyphicon-camera glyphicon-camera-input icon"></span></a>
<input id="imageInput" multiple type="file" class="hidden" name="files" />
</div>
</div>
</div>
<div class="col-sm-6 text-right">
<div class="text-right">
<button id="btnCancel" class="btn btn-default" type="button">Cancel</button>
<a id="aSubmitStatus" class="btn btn-primary">Submit</a>
<input id="btnSubmitStatus" type="submit" class="btn hidden" />
</div>
</div>
</div>
</form>
和jQuery / Javascript ..
function CreateStatus() {
var status = $('#tbStatus').val();
var formData = new FormData();
var data = {
files: "", //this is where i'm having the issue? I'm not sure what to do here.
status: status
}
$.ajax({
type: 'POST',
url: '/Webservices/StatusWebService.asmx/CreateStatus',
data: JSON.stringify(data),
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (result) {
console.log(result.d);
},
error: function (errorThrown) {
console.log(errorThrown);
}
});
}
和网络服务
[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public async Task<string> CreateStatus(string status, IEnumerable<HttpPostedFileBase> files)
{
//everything here needed to save to db/amazon s3
}
如果我删除了HttpPostedFileBase和相关代码,我就可以很好地调用webservice,只是将问题传递给webservice时会出现问题。
非常感谢任何帮助!!