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

Showing previous selected files after failed postback

4 Answers 290 Views
Upload
This is a migrated thread and some comments may be shown as answers.
Peter
Top achievements
Rank 1
Peter asked on 23 Jun 2017, 05:39 PM

I have a simple form:

@Model MyViewModel

<form method="post" action='@Url.Action("Submit")'>

    <div class="demo-section k-content">

        @Html.TextBoxFor(x => x.SomeRequiredField);

        @(Html.Kendo().Upload() .Name("files") .HtmlAttributes(new { aria_label = "files" }) )

        <p style="padding-top: 1em; text-align: right"><input type="submit" value="Submit" class="k-button k-primary" /></p>

    </div>

</form>

 

public ActionResult Submit(MyViewModel vm, IEnumerable<HttpPostedFileBase> files){

    if(ModelState.Valid) {

        ... do stuff

    } else {

        return View(vm);

    }

}

 

If I select a bunch of files in my upload control, and push the Submit button, suppose validation failed and the view is posted back, however my selected files are lost and I have to reselect them.

How do I restore the previously selected files in the file upload control (synchronous mode) when the form fails validation and is posted back?

 

4 Answers, 1 is accepted

Sort by
0
Peter
Top achievements
Rank 1
answered on 23 Jun 2017, 05:44 PM
I also want to mention I know this can be achieved with the upload control in async mode. However my uploaded files are part of a parent object which means they must be submitted together with the rest of the form. Therefore I need a way of preserving selected files when using the file upload control in synchronous mode.
0
Ivan Danchev
Telerik team
answered on 27 Jun 2017, 08:20 AM
Hello Peter,

The Upload in synchronous mode cannot be configured to persist the selected files after the page is submitted. In async mode this can be done through the .Files() configuration option, but there is no alternative to it in synchronous mode.

Regards,
Ivan Danchev
Progress Telerik
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
0
Dave
Top achievements
Rank 1
answered on 11 Oct 2018, 11:03 PM
I just wanted to confirm if this is still the case. I have an Upload control as part of a submit (along with other form fields) and if an error occurs in the controller's action method and I redirect back to the razor view along with the view model, the files that the user had previously selected in the Upload control are gone. Is there no way to persist the files the user had selected? It's an inconvenience to have to force the user to re-select all the files they wanted to upload.
0
Nencho
Telerik team
answered on 15 Oct 2018, 02:41 PM
Hello Dave,

Yes, the case is still the same, and the Upload in synchronous mode cannot be configured to persist the selected files after the page is submitted.

Regards,
Nencho
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
Upload
Asked by
Peter
Top achievements
Rank 1
Answers by
Peter
Top achievements
Rank 1
Ivan Danchev
Telerik team
Dave
Top achievements
Rank 1
Nencho
Telerik team
Share this question
or