我正在使用 filepond 插件批量上传文件。上传的文件被保存到缓存中。现在我想点击删除按钮来删除我缓存中的相应文件。我想知道前端文件的名称或id应该如何传输到控制器?或者控制器在表单提交时如何获取filepond文件,也可以解决我目前的问题。
这是我使用的 c# 的代码:
[HttpPost]
public ActionResult SaveFiles()
{
if (Request.Files.Count > 0)
{
var file = Request.Files[0];
if (file != null && file.ContentLength > 0)
{
UploadedFiles uploadedFiles = new UploadedFiles()
{
UserName = UserSession.CurrentUser.UserName,
PostedFile = file
};
uploadedFilesList.Add(uploadedFiles);
}
}
return Json(true);
}
[HttpDelete]
public ActionResult RemoveFile()
{
// How to put the id or name of the deleted file into this action?
return Json(true);
}
这是我使用的 html 和 javascript 的代码
<div class="controls">
<input type="file" class="filepond" name="filepond" multiple
data-max-file-size="50MB" data-max-files="10">
<p class="help-block">Optional.</p>
</div>
<link href="https://unpkg.com/filepond-plugin-image-preview/dist/filepond-plugin-image-preview.min.css" rel="stylesheet" />
<link href="https://unpkg.com/filepond/dist/filepond.min.css" rel="stylesheet">
<link href="https://unpkg.com/filepond-plugin-file-poster/dist/filepond-plugin-file-poster.css" rel="stylesheet">
<script src="https://unpkg.com/filepond-plugin-file-encode/dist/filepond-plugin-file-encode.min.js"></script>
<script src="https://unpkg.com/filepond-plugin-file-validate-size/dist/filepond-plugin-file-validate-size.min.js"></script>
<script src="https://unpkg.com/filepond-plugin-image-exif-orientation/dist/filepond-plugin-image-exif-orientation.min.js"></script>
<script src="https://unpkg.com/filepond-plugin-image-preview/dist/filepond-plugin-image-preview.min.js"></script>
<script src="https://unpkg.com/filepond/dist/filepond.min.js"></script>
<script>
FilePond.registerPlugin(
FilePondPluginImagePreview,
FilePondPluginImageExifOrientation,
FilePondPluginFileValidateSize
);
// Select the file input and use create() to turn it into a pond
FilePond.create(document.querySelector('.filepond'));
FilePond.setOptions({
server: {
process: '/List/SaveFiles',
revert: '/List/RemoveFile',
}
});
</script>