kendo 上传 MVC 控制器模型绑定

kendo upload MVC controller model binding

我无法将 kendo 上传“删除文件”功能的数据绑定到后端的控制器中。

这是我的 kendo ts 组件:

  intercept(req: HttpRequest<any>,next: HttpHandler): Observable<HttpEvent<any>> 
  {
    if (req.url === "email/saveAttachment") {
      const events: Observable<HttpEvent<any>>[] = [0, 30, 60, 100].map((x) =>
        of(<HttpProgressEvent>
          {
          type: HttpEventType.UploadProgress,
          loaded: x,
          total: 100,
          }));

      const success:any = of(new HttpResponse({ status: 200 }));
       events.push(success);
       console.log(success)
      
       return concat(...events);

    }
    if (req.url === 'email/rempveAttachment') {
      return of(new HttpResponse({ status: 200 }));
    }
    return next.handle(req);
  };

这是我的 .net5 mvc 控制器:

 public class EmailController: ControllerBase
    {
        [HttpPost("saveAttachment")]
        public async Task<IActionResult> SaveAttachment(List<IFormFile> files) //I am able to bind data here 
        {
            foreach (IFormFile file in files)
            {
                Helpers.FileHelper.CopyFileLocally(file.OpenReadStream(), $"Attachments/{file.FileName}");
            }

           await Task.Yield();
           return Ok();
        }


        [HttpPost("rempveAttachment")]
        public async Task<IActionResult> RempveAttachment(List<string> fileNames) // here i am getting null. 
        {
            Helpers.FileHelper.DeleteFileLocally(fileNames[0]);
           
            await Task.Yield();
            return Ok();
        }
}

我尝试使用字符串,但它也没有绑定。我也无法通过检查请求有效负载来弄清楚。如果您有任何建议,请告诉我,在此先感谢您。

这里还有有效负载图像: enter image description here

我能够通过以下绑定解决这个问题。我不确定它是否针对我的情况。

public async Task<IActionResult> RempveAttachment(IFormCollection fileNames){
      string fileNameKey= fileNames["fileNames"].Single(); 
        await Task.Yield();
        return Ok();
}