Issue
I am having trouble to bind the data for the kendo upload "remove file" functionality into the controller on the back end.
Here is my kendo ts component looks like:
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);
};
Here is my .net5 mvc controller:
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();
}
}
I tried using the string but it doesn't bind either. I could not figure it out by inspecting the Request payload either. Please let me know if you have any suggestions and thank you in advance.
Also here is the payload image: enter image description here
Solution
I was able to solve this problem with the following binding. I am not sure if it was specific to my case.
public async Task<IActionResult> RempveAttachment(IFormCollection fileNames){
string fileNameKey= fileNames["fileNames"].Single();
await Task.Yield();
return Ok();
}
Answered By - Stanislav Mozolevskiy
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.