Basic Upload not working

13 posts, 0 answers
  1. Joe
    Joe avatar
    167 posts
    Member since:
    May 2012

    Posted 08 Dec 2016 Link to this post

    So I'm doing something fairly simple. Using the Upload component...  Here is my View code:

    @{
        ViewBag.Title = "Index";
    }
     
    <h2>Index</h2>
     
    <div style="width: 45%">
        <form method="post" id="csvForm" action='@Url.Action("Result", "Home")'>
            <div class="k-content">
                @(Html.Kendo().Upload()
                    .Name("files")
                    .Multiple(false)
                )
                <span class="k-invalid-msg" data-for="files"></span>
                <p></p>
     
                <div style="text-align: right">
                    @(Html.Kendo().Button()
                          .Name("submit")
                          .Content("Upload")
                          .HtmlAttributes(new { type = "submit", @class = "k-button k-primary" })
                          )
                </div>
            </div>
     
            <div id="status"></div>
        </form>
    </div>

     

    And my controller is also simple:

    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using BankFTP.Attributes;
     
    namespace BankFTP.Controllers
    {
        [MustBeAuthorized]
        public class HomeController : Controller
        {
            // GET: Home
            public ActionResult Index()
            {
                return View();
            }
     
            public ActionResult Result(IEnumerable<HttpPostedFileBase> files)
            {
                if (files == null) { return RedirectToAction("Index"); }
                HttpPostedFileBase file = files.ToArray()[0];
     
                string thisFile = file.FileName;
                FileInfo thisFileInfo = new FileInfo(thisFile);
     
     
     
                return View();
            }
        }
    }

     

    Nothing much to it really, and matches what the Basic Demo shows, except the IEnumerable<HttpPostedFileBase> parameter to the Action has a Count of 0, even though a file is chosen before pressing the Upload button.  I know this should be fairly simple, and I've done it before, but I just don;t know what I'm missing here...

  2. Joe
    Joe avatar
    167 posts
    Member since:
    May 2012

    Posted 08 Dec 2016 in reply to Joe Link to this post

    On the off chance that my custom attribute was blocking it, I removed it... the parameter files still has a count of 0...  Which is odd, I would expect that if it didn't work, files would be null, but it's not.  Just an empty collection.
  3. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2211 posts

    Posted 09 Dec 2016 Link to this post

    Hello Joe,

    This is indeed strange. The provided configuration is correct and is working as expected on our end. If the issue is still persisting, you could send us small isolated runnable example, where it is reproducing, so we could take a look.

    Regards,
    Dimiter Madjarov
    Telerik by Progress
    Telerik UI for ASP.NET MVC is ready for Visual Studio 2017 RC! Learn more.
  4. Joe
    Joe avatar
    167 posts
    Member since:
    May 2012

    Posted 09 Dec 2016 Link to this post

    Even an empty MVC app, with all the kendo js scripts and css files is 26 MB, so I cannot attach it here.  But here is a dropbox link you can download it from.  1 controller, and 2 views...  Does the same exact thing, select a file but the resultant files parameter is an ampty collection.  Not a null, but an empty collection.
  5. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2211 posts

    Posted 09 Dec 2016 Link to this post

    Hello Joe,

    Thank you for providing the runnable project. First thing I noticed is that it misses the required script files for Kendo UI, which results in the widgets not being initialized. You should add jquery.min.js and kendo.all.min.js.

    Leaving this aside, I was unable to reproduce the mentioned behavior. The files are submitted as expected to the Result action.

    Regards,
    Dimiter Madjarov
    Telerik by Progress
    Telerik UI for ASP.NET MVC is ready for Visual Studio 2017 RC! Learn more.
  6. Joe
    Joe avatar
    167 posts
    Member since:
    May 2012

    Posted 09 Dec 2016 in reply to Dimiter Madjarov Link to this post

    In my original project, they are included.  You'd think the Telerik MVC Wizard would actually include everything it needs, but it doesn't.  

    So you're saying you cannot reproduce it and the code I sent works, whereas I have two projects here where it doesn't work at all.  Well that just make no sense whatsoever, but it doesn't surprise me... These Telerik components have been a thorn in my side since we ordered them... Whatever, I'll just not use the upload control since basic HTML file upload works completely hitch free.

  7. Dimiter Madjarov
    Admin
    Dimiter Madjarov avatar
    2211 posts

    Posted 09 Dec 2016 Link to this post

    Hello Joe,

    The synchronous Upload widget does not differ from a regular <input type="file" /> element, as it still depends on submitting the form to send the files and does not perform any request on it's own. If you would like, I could attach a screen capture demonstrating the successfully submitted file with and without the usage of the widget.

    Let me know if I could provide further assistance regarding the case.

    Regards,
    Dimiter Madjarov
    Telerik by Progress
    Telerik UI for ASP.NET MVC is ready for Visual Studio 2017 RC! Learn more.
  8. Wes
    Wes avatar
    2 posts
    Member since:
    Jun 2017

    Posted 11 Jul in reply to Dimiter Madjarov Link to this post

    Was there ever a solution to this?

    I am having exactly the same problem trying to use the demo.  

     
    @using Kendo.Mvc.UI
     
    @{
        ViewBag.Title = "Index";
    }
     
    <h2>Index</h2>
     
    <div class="box">
        <h4>Information</h4>
        <p>
            The Upload can be used as a drop-in replacement
            for file input elements. This "synchronous" mode does not require
            special handling on the server.
        </p>
    </div>
    <form method="post" action='@Url.Action("Submit")'>
        <div class="demo-section k-content">
            @(Html.Kendo().Upload()
                  .Name("files").Multiple(true).Directory(true)
                  .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(IEnumerable<HttpPostedFileBase> files) -> files is always 0-length array
       {
           if (files != null)
           {
               TempData["UploadedFiles"] = GetFileInfo(files);
           }
     
           return Save(files);
       }
  9. Ivan Danchev
    Admin
    Ivan Danchev avatar
    1207 posts

    Posted 13 Jul Link to this post

    Hello Wes,

    I see from the Upload configuration you posted that you are using the Directory upload functionality. It is available since R2 2017 so please make sure you have the Kendo.Mvc.dll from this release or newer referenced and you are loading the same version of the Kendo UI js and CSS files.
    At my end the Upload works as expected and the files within the selected folder are sent to the Submit action as can be see in this screenshot.

    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.
  10. Wes
    Wes avatar
    2 posts
    Member since:
    Jun 2017

    Posted 13 Jul in reply to Ivan Danchev Link to this post

    Yes, I just downloaded it this week.  Running the demo.

    I have 2017.2.621.545 as the version of Kenvdo.Mvc  (Runtime Version v4.0.30319)

    I am trying to mimic the functionality of the demo here:

    http://demos.telerik.com/aspnet-mvc/upload

    However, my view looks very different than the page, and I have been chasing my tail trying to work through all the different setup requirements just to create a demo project.

    What would *REALLY* be helpful is either a complete, start-from-zero set of instructions on how to create that demo page, or a downloadable project that would generate a similar demo.

  11. Ivan Danchev
    Admin
    Ivan Danchev avatar
    1207 posts

    Posted 14 Jul Link to this post

    Hello Wes,

    Attached you can find a sample runnable project, which demonstrates the Upload's functionality as in our live demo, but with the wrapper's directory upload enabled (as in the code snippet you posted). Within the project there's an Images folder that you can test the Upload with. 

    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.
  12. Darren
    Darren avatar
    9 posts
    Member since:
    Mar 2013

    Posted 23 Jul in reply to Wes Link to this post

    I'm not sure if I'm overlooking the obvious, but none of the examples posted include the required

     

    enctype="multipart-form-data"

     

    for uploading files. Is that just an omission in your post(s), or is that what is actually in your project? If the latter, unless you are using AJAX uploads, you'll never see any files in the form submission.

  13. Darren
    Darren avatar
    9 posts
    Member since:
    Mar 2013

    Posted 23 Jul in reply to Darren Link to this post

    Sorry, that should have been

    enctype="multipart/form-data"

    Would be nice if there were an edit option for forum posts...

Back to Top