Basic Upload not working

7 posts, 0 answers
  1. Joe
    Joe avatar
    149 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
    149 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
    2207 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
    149 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
    2207 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
    149 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
    2207 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.
Back to Top