Showing previous selected files after failed postback

5 posts, 0 answers
  1. Peter
    Peter avatar
    14 posts
    Member since:
    Dec 2013

    Posted 23 Jun 2017 Link to this post

    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?

     

  2. Peter
    Peter avatar
    14 posts
    Member since:
    Dec 2013

    Posted 23 Jun 2017 in reply to Peter Link to this post

    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.
  3. Ivan Danchev
    Admin
    Ivan Danchev avatar
    1712 posts

    Posted 27 Jun 2017 Link to this post

    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.
  4. Dave
    Dave avatar
    42 posts
    Member since:
    Jan 2008

    Posted 11 Oct 2018 in reply to Ivan Danchev Link to this post

    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.
  5. Nencho
    Admin
    Nencho avatar
    1808 posts

    Posted 15 Oct 2018 Link to this post

    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.
Back to Top