Using Upload on Kendo Window

2 posts, 0 answers
  1. Jaesoon
    Jaesoon avatar
    56 posts
    Member since:
    Oct 2012

    Posted 09 Apr 2016 Link to this post

    I'm trying to add an upload feature on a Kendo Window which uses forms, so a user can fill in details, attach a file, and press save - which will post to the controller and save the file and associated data and close the window.

    After trying to get the upload to work using Ajax.BeginForm (as below), 

    @using (Ajax.BeginForm("Save", "Manage", null, new AjaxOptions {HttpMethod = "POST"}, new { enctype = "multipart/form-data", @id = "form", target = "_self"  }))

    i kept getting a null value (for the file parameter) and came to the conclusion that the upload control only works for Html.BeginForm (as below)

    @using (Html.BeginForm("Save", "Manage", FormMethod.Post, new { enctype = "multipart/form-data" }))

    and can see the file parameter coming through when i use it.

    However, using Html.BeginForm will force a reload of a page (by redirection) which I do not want to happen. Also I do not want asynchronous uploading to happen as saving the file requires some additional data on the form before it can be saved.

    The controller looks like this

    public ActionResult Save (Model model, IEnumerable<HttpPostedFileBase> file)

    Currently for any other screen which does not use the Kendo Uploader, I am using Ajax.BeginForm which posts to the controller and use JavaScript to close the Kendo Window.

    What is the correct way of adding a Kendo Upload control onto a Kendo Window and to save / upload the file and close the window?

    And if not is there a way to emulate the Kendo Upload's async method when saving the form?

    Otherwise is there a way to use Html.BeginForm on a window and stop it from redirecting to a different page?
  2. Dimiter Madjarov
    Dimiter Madjarov avatar
    2213 posts

    Posted 12 Apr 2016 Link to this post

    Hello Jaesoon,

    A file cannot be uploaded via Ajax.BeginForm. This is not supported by the framework, so there is no workaround that I could suggest using this approach.

    I would recommend using the asynchronous Kendo UI Upload widget. The rest of the form data could be send along with the uploaded file as additional metadata using the following approach.

    Dimiter Madjarov
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top