需要帮助,我如何在ASP.NET核心rc2 web api上传文件.当我使用asp.net 4.5它使用此代码:
@{
ViewBag.Title = "Home Page";
}
<div>
<input type="file" name="upload" id="uploadFile" /><br />
<button id="submit">?????????</button>
</div>
@section scripts{
<script type="text/javascript">
$('#submit').on('click', function (e) {
e.preventDefault();
var files = document.getElementById('uploadFile').files;
if (files.length > 0) {
if (window.FormData !== undefined) {
var data = new FormData();
for (var x = 0; x < files.length; x++) {
data.append("file" + x, files[x]);
}
$.ajax({
type: "POST",
url: 'api/values/post',
contentType: false,
processData: false,
data: data,
success: function (result) {
alert(result);
}, …Run Code Online (Sandbox Code Playgroud)