I have followed some of the examples for declaring my MVC controller method for use with the Upload component. My upload handler declaration is as follows:
public ActionResult Upload(IEnumerable<HttpPostedFileBase> attachments, long inventoryID, long imageType)
{
}
I have set my Upload control to use Async. However, whenever I try to upload a file, the attachments parameters is always passed null.
I have also tried:
- Renaming attachments to files
- Declaring IEnumerable<HttpPostedFileBase> as IEnumerable<HttpPostedFile>
- Declaring the attachments parameter as both HttpPostedFileBase and HttpPostedFile (singular
I have written some JavaScript (as the Upload event) to pass the additional parameters (inventoryID and imageType) which are always passed successfully.
function imageUploadUpload(e) {
e.data = { inventoryID : @Model.InventoryID, imageType: imageType };
}
I have tried removing the Upload event/handler to see if this makes a difference, but still have the same problem.
Any idea what is going on?
Thank you.
*** EDIT ***
I found the solution here. The name of the Upload component must match the name of the parameter that holds the HttpPostedFileBase. I had named my Upload component imageUpload. When I renamed the parameter to imageUpload, it worked fine!
9 Answers, 1 is accepted
I can confirm that after naming the parameter in the controller the exact same name as what I named the KendoUI upload control, it worked. Thanks Steven.
<input name="file" id="fileUploader" type="file" />
public ActionResult UploadFile(HttpPostedFileBase file, String subject, String doc, String ref)
{
}
that is a problem if you want to use the uploader in a patial view that is used in multiple tabs or pills on the same page.
ex. i have a product "dress" and the dress had multiple "finishes", ex red, blue and yellow.
i made tabs per finish and now i want to upload picuters on differet tabs.
my uploader requires a unique identifier per tab, so it's called "uploader_blue", "uploader_red",...
however, the controler and the action is always the same. i cant make 5 actions with the same name and different parameters.......
Hello elke,
In such cases you should use the async.saveField configuration option and specify it to match the name of the controller action parameter. This will allow you to keep the different names of the uploads.
Regards,Dimiter Madjarov
Telerik
I had a silly typo in action signature - as - DocumentUpload(IEnumerable<HttpPostedFile> files)
and the files collection was always empty. It took me 4 hours to figure out the type should have been FileBase as in below..
DocumentUpload(IEnumerable<HttpPostedFileBase> files)
--
"The name of the Upload component must match the name of the parameter
that holds the HttpPostedFileBase..."
I don't why the telerik official Upload documentation/sample
NEVER notice the developer this point explicitly(not just "files") ???
Upload / Asynchronous Upload
https://demos.telerik.com/aspnet-mvc/upload/async
public ActionResult Async_Save(IEnumerable<HttpPostedFileBase> files)
{
// The Name of the Upload component is "files"
-> "files" parameter name must same as the name(element attribute - "name") of the Upload component.
<input type="file" name="files" /> IEnumerable<HttpPostedFileBase> files
<input type="file" name="file1" /> IEnumerable<HttpPostedFileBase> file1
<input type="file" name="file2" /> IEnumerable<HttpPostedFileBase> file2
async.saveUrl
https://docs.telerik.com/kendo-ui/api/javascript/ui/upload/configuration/async.saveurl
-> have no any description about this.
so sad...
Best regards
Chris
I am sorry for the inconvenience you have experienced and thank you for your constructive feedback!
We will consider adding more details and explicitly pointing out that the name of the parameter that holds HttpPostedFileBase should be the same as the name of the Upload component.
Regards,
Petar
Progress Telerik