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

How to asynchronously send all the uploaded files at once in MVC Telerik Upload Control?

1 Answer 95 Views
Upload
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
M
Top achievements
Rank 1
M asked on 19 Apr 2012, 10:16 AM

I am using telerik file upload control for my MVC3 application. I am using its asynchronous feature to upload the files. Below is the code that I am using.

@(Html.Telerik().Upload()
       
.Name("files")
       
.ShowFileList(true)    
       
.Multiple(true)                                    
       
.Async(
                async
=> async
               
.Save("Save", "MyController")
               
.AutoUpload(false)
               
.Remove("Remove", "MyController")                            
           
)
   
)

[HttpPost]
       
public ActionResult Save(IEnumerable<HttpPostedFileBase> files)
       
{            
           
foreach (var file in files)
           
{
               
// Some browsers send file names with full path. We only care about the file name.
               
var fileName = Path.GetFileName(file.FileName);
               
var destinationPath = Path.Combine(Server.MapPath("~/App_Data"), fileName);

                file
.SaveAs(destinationPath);
           
}
           
return Content("");
       
}

The above piece of code will generate two buttons viz. "Select" and "Upload files". After selecting 4 files and pressing "upload files" button, the telerik calls the action method 4 times asynchronously (which is bad). What I wanted was the method should be called only once and all the 4 files should be send to the method at once (as I am accepting list of files).

So, How can I achieve this in Html.Telerik().Upload() control?

Also, I will be showing this control in my Html.Telerik().Window(), So I will need to send uploaded data to my parent page. Any helps how to do this too?

Thanks.

1 Answer, 1 is accepted

Sort by
0
Swapnadip
Top achievements
Rank 1
answered on 27 Apr 2012, 12:53 PM
Try this


@(
Html.Telerik().Upload()
.Name("files")
       
.ShowFileList(true)   
       
.Multiple(true)                                   
       
.Async(
                async
=> async
               
.Save("Save", "MyController")
               
.AutoUpload(true)
               
.Remove("Remove", "MyController")      
   
)


Just set the AutoUpload true
Tags
Upload
Asked by
M
Top achievements
Rank 1
Answers by
Swapnadip
Top achievements
Rank 1
Share this question
or