Showing previous selected files after failed postback

3 posts, 0 answers
  1. Peter
    Peter avatar
    13 posts
    Member since:
    Dec 2013

    Posted 23 Jun 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
    13 posts
    Member since:
    Dec 2013

    Posted 23 Jun 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
    1324 posts

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