This is a migrated thread and some comments may be shown as answers.

Basic Upload not working

12 Answers 472 Views
Upload
This is a migrated thread and some comments may be shown as answers.
Joe
Top achievements
Rank 1
Joe asked on 08 Dec 2016, 08:29 PM

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...

12 Answers, 1 is accepted

Sort by
0
Joe
Top achievements
Rank 1
answered on 08 Dec 2016, 08:55 PM
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.
0
Dimiter Madjarov
Telerik team
answered on 09 Dec 2016, 12:01 PM

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.
0
Joe
Top achievements
Rank 1
answered on 09 Dec 2016, 02:40 PM
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.
0
Dimiter Madjarov
Telerik team
answered on 09 Dec 2016, 03:13 PM

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.
0
Joe
Top achievements
Rank 1
answered on 09 Dec 2016, 03:17 PM

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.

0
Dimiter Madjarov
Telerik team
answered on 09 Dec 2016, 03:55 PM

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.
0
Wes
Top achievements
Rank 1
answered on 12 Jul 2017, 12:36 AM
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);
   }
0
Ivan Danchev
Telerik team
answered on 13 Jul 2017, 03:09 PM
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.
0
Wes
Top achievements
Rank 1
answered on 13 Jul 2017, 04:01 PM

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.

0
Ivan Danchev
Telerik team
answered on 14 Jul 2017, 02:19 PM
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.
0
Darren
Top achievements
Rank 2
answered on 23 Jul 2017, 08:57 PM

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.

0
Darren
Top achievements
Rank 2
answered on 23 Jul 2017, 08:59 PM

Sorry, that should have been

enctype="multipart/form-data"

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

Tags
Upload
Asked by
Joe
Top achievements
Rank 1
Answers by
Joe
Top achievements
Rank 1
Dimiter Madjarov
Telerik team
Wes
Top achievements
Rank 1
Ivan Danchev
Telerik team
Darren
Top achievements
Rank 2
Share this question
or