我正在尝试在我的.Net Core MVC应用程序中使用JqWidgets文件上传,但是它似乎并未将文件传递给控制器。这是我的代码
$(document).ready(function () {
GetFileTypes();
$('#jqxFileUpload').jqxFileUpload({
width: 300,
browseTemplate: 'success',
uploadTemplate: 'primary',
cancelTemplate: 'danger',
uploadUrl: "@Url.Action("Upload","ProcessFile")",
fileInputName: 'fileToUpload',
localization: {
browseButton: 'Select File'
}
});
$('#jqxLoader').jqxLoader('open');
});
HTML:
<form role="form">
<div class="row">
<div class="col-xs-6 col-md-6 col-lg-6">
<div class="form-group">
<div id="jqxFileUpload">
</div>
</div>
</div>
</div>
</form>
控制器:
[HttpPost]
public async Task<IActionResult> Upload(List<IFormFile> files)
{
long size = files.Sum(f => f.Length);
// full path to file in temp location
var filePath = Path.GetTempFileName();
foreach (var formFile in files)
{
if (formFile.Length > 0)
{
using (var stream = new FileStream(filePath, FileMode.Create))
{
await formFile.CopyToAsync(stream);
}
}
}
// process uploaded files
// Don't rely on or trust the FileName property without validation.
return Ok(new { count = files.Count, size, filePath });
}
当调试器点击控制器时,IFormFile列表保持为空。请让我知道我在这里到底想念什么。
仅供参考:我尝试使用在HTML中为表单标签设置 enctype =“ multipart / form-data” 的输入type =“ file”,并且效果很好。