Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net mvc FilePond如何将已删除文件的名称或id作为参数传递给控制器?_Asp.net Mvc_File Upload_Filepond - Fatal编程技术网

Asp.net mvc FilePond如何将已删除文件的名称或id作为参数传递给控制器?

Asp.net mvc FilePond如何将已删除文件的名称或id作为参数传递给控制器?,asp.net-mvc,file-upload,filepond,Asp.net Mvc,File Upload,Filepond,我正在使用filepond插件批量上传文件。上载的文件将保存到缓存中。现在我想单击delete按钮删除缓存中相应的文件。我想知道如何将前端文件的名称或id传输到控制器? 或者在提交表单时控制器如何获取filepond文件,这也可以解决我当前的问题 以下是cI使用的代码: [HttpPost] public ActionResult SaveFiles() { if (Request.Files.Count > 0) {

我正在使用filepond插件批量上传文件。上载的文件将保存到缓存中。现在我想单击delete按钮删除缓存中相应的文件。我想知道如何将前端文件的名称或id传输到控制器? 或者在提交表单时控制器如何获取filepond文件,这也可以解决我当前的问题

以下是cI使用的代码:

    [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代码

可选

FilePond.registerPlugin FilePonPluginImagePreview, FilePondPluginImageExiforOrientation, FilePondPluginFileValidateSize ; //选择文件输入并使用“创建”将其转换为池塘 FilePond.createdocument.querySelector'.FilePond'; FilePond.setOptions{ 服务器:{ 进程:'/List/SaveFiles', 还原:'/List/RemoveFile', } };
您不应该使用ActionResult

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

通常,如果不更改Filepond还原设置中的任何内容,则文件id将在请求正文中作为简单文本发送。要获取此id,您需要执行以下操作:

public async Task<IActionResult> OnDelete()
{
    var fileId = "";
    using (StreamReader reader = new StreamReader(Request.Body, Encoding.UTF8))
    {
        fileId = await reader.ReadToEndAsync();
    }

    bool isDeleted = false;

    // Do delete your file

    if (isDeleted)
        return new ContentResult() { Content = "deleted" };
    else
        return new ContentResult() { Content = "error", StatusCode = 500 };
}
这是RazorPage的ASP.NET核心版本