This is a migrated thread and some comments may be shown as answers.

Upload control : upload file twice, in ajax and with final POST submit button

1 Answer 927 Views
Upload
This is a migrated thread and some comments may be shown as answers.
Richard
Top achievements
Rank 1
Richard asked on 04 Feb 2020, 10:08 AM

Hello,

I have posted the following question on Stack Overflow :

https://stackoverflow.com/questions/60001543/telerik-upload-control-in-mvc-core-upload-file-twice-in-ajax-and-with-final

Basically, I need to be able to post the file in a Telerik Upload control twice : in async mode (works fine), and at final POST of the form with a submit button. The file is not posted with the submit button in form, despite the form seem to be correctly declared.

I guess this is due to the fact to have enabled Async mode on the upload control.

The control is defined like this :

@(Html.Kendo().Upload()
    .Name("fileUpload")
    .Multiple(false)
    .Async(a => a
        .Save("AnalyzeFile", "Request")
        .AutoUpload(true)
    )
    .Events(e => e.Success("onUploadOperationSuccess"))
    .Validation(validation => validation.AllowedExtensions(new[] { ".csv" }))
    .HtmlAttributes(new { style = "width:100%" }))

 

and the form :

@using (Html.BeginForm("Save", "Request", FormMethod.Post, new { @class = "form-horizontal", id = "requestForm", enctype="multipart/form-data" }))
{
    ...
    <button id="finalSubmit" type="submit" class="k-button k-primary">Valider</button>
}

 

You can find more details (but the most important part is here) in previous link.

Thanks for help

1 Answer, 1 is accepted

Sort by
0
Ivan Danchev
Telerik team
answered on 06 Feb 2020, 07:37 PM

Hello Richard,

The Upload's async mode is designed to send the file on selection (or after confirmation with the autoUpload option set to "false"). It is not designed to be used in a form. The sync mode is to be used when submitting the files with form, but this mode does not work with a handler and does not make a request to the server on file selection. In this mode the Upload works as a standard <input type="file"> and the files are sent with the form submission. 

That being said, I don't think we can come up with a workaround for your scenario. There is a thread in stackoverflow: https://stackoverflow.com/a/35200162

in which Murat demonstrates how the selected files can be sent with an AJAX request, but this essentially sends the form data not just the files Thus, I am not sure whether it is applicable to your case, since it would mean sending the form data twice.

Regards,
Ivan Danchev
Progress Telerik

Get quickly onboarded and successful with Telerik UI for ASP.NET Core with the dedicated Virtual Classroom technical training, available to all active customers.
hines
Top achievements
Rank 1
commented on 26 Jan 2024, 10:09 PM | edited

  j
Tags
Upload
Asked by
Richard
Top achievements
Rank 1
Answers by
Ivan Danchev
Telerik team
Share this question
or