FilePond, как передать имя или идентификатор удаленного файла в качестве параметра в контроллер? - PullRequest
0 голосов
/ 11 октября 2019

Я использую плагин filepond для массовой загрузки файлов. Загруженные файлы сохраняются в кеш. Теперь я хочу нажать кнопку удаления, чтобы удалить соответствующий файл в моем кэше. Я хочу знать, как имя или идентификатор переднего файла должны быть переданы в контроллер? Или как контроллер может получить файл 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>

1 Ответ

0 голосов
/ 11 октября 2019

Вы не должны использовать ActionResult.

    [HttpDelete]
    public string RemoveFile(int id)
    {
       return "Deleted!";
    }
...