Delete method always receives null

1 Answer 12 Views
Upload
Dean
Top achievements
Rank 1
Iron
Veteran
Iron
Dean asked on 24 Sep 2021, 05:33 PM

Has anyone else had a problem with removing files using TelerikUpload?  Upload works fine, but when attempting to remove it hits the Remove method, but the files parameter is null.  I have tried changing the parameter type from string to string[], IFormFile and IEnumerable<IFormFile>.  I've tried changing the parameter name (and corresponding RemoveField), and nothing makes any difference.  I can add a second, custom parameter, and that works ok.  I just can't get a value for files.

Selected markup/code:

                        <TelerikUpload SaveUrl="@(AddDocumentApi())"
                                   Multiple="true"
                                   RemoveUrl="@(RemoveDocumentApi())"
                                   OnUpload="OnUploadHandler"
                                   OnRemove="OnRemoveHandler"
                                   OnSuccess="OnSuccessHandler"
                                   WithCredentials="true"
                                   AllowedExtensions="@AllowedExtensions" />

 

        public string RemoveDocumentApi() => $"{AddDocumentApiBase}/deletedocument";

        [HttpPost("deletedocument")]
        public async Task<IActionResult> DeleteDocument(string files)
        {
             // Hits a breakpoint here but files is null
            return new EmptyResult();
        }

Marin Bratanov
Telerik team
commented on 28 Sep 2021, 06:54 PM

This sounds like a routing problem. You can use the Network tab of the browser dev tools to see what goes out of the browser, what URL it goes to, what form fields it has, so you can investigate how such a request is handled by the server. You can even replay it with tools like Fiddler so you can easily debug the backend.
Dean
Top achievements
Rank 1
Iron
Veteran
Iron
commented on 04 Oct 2021, 09:14 AM

Thanks Martin but I don't think there is a problem with routing, because as I said, it hits a breakpoint in my controller, but the files parameter is null.  I can see that the file name is being sent correctly.  I've added two further images to clarify.
Dean
Top achievements
Rank 1
Iron
Veteran
Iron
commented on 04 Oct 2021, 09:15 AM

In the images I have an additional parameter of folder, but the problem is the same with or without it
Dean
Top achievements
Rank 1
Iron
Veteran
Iron
commented on 04 Oct 2021, 09:21 AM

Fixed this - I had to add [FromForm] before the parameter

public async Task<IActionResult> DeleteDocument([FromForm] string files)

1 Answer, 1 is accepted

Sort by
0
Accepted
Dean
Top achievements
Rank 1
Iron
Veteran
Iron
answered on 04 Oct 2021, 09:21 AM

Fixed this - I had to add [FromForm] before the parameter

public async Task<IActionResult> DeleteDocument([FromForm] string files)

Tags
Upload
Asked by
Dean
Top achievements
Rank 1
Iron
Veteran
Iron
Answers by
Dean
Top achievements
Rank 1
Iron
Veteran
Iron
Share this question
or