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

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

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.
Dimiter Madjarov
Telerik by Progress

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.
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.
Dimiter Madjarov
Telerik by Progress

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);
}
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

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

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.

Sorry, that should have been
enctype="multipart/form-data"
Would be nice if there were an edit option for forum posts...