Re: MVC Ajax Uploader

  •  02-28-2013, 2:49 PM

    Re: MVC Ajax Uploader

    Hi,

     

    To achieve this, you do not need to submit the form. you can refer to example page "multiple_files_upload". it has the same code. 

     

    1. public ActionResult multiple_files_upload(string myuploader)  
    2.         {  
    3.             using (CuteWebUI.MvcUploader uploader = new CuteWebUI.MvcUploader(System.Web.HttpContext.Current))  
    4.             {  
    5.                 uploader.UploadUrl = Response.ApplyAppPathModifier("~/UploadHandler.ashx");  
    6.                 //the data of the uploader will render as <input type='hidden' name='myuploader'>   
    7.                 uploader.Name = "myuploader";  
    8.                 uploader.AllowedFileExtensions = "*.jpg,*.gif,*.png,*.bmp,*.zip,*.rar";  
    9.                 //allow select multiple files  
    10.                 uploader.MultipleFilesUpload = true;  
    11.                 //tell uploader attach a button  
    12.                 uploader.InsertButtonID = "uploadbutton";  
    13.                 //prepair html code for the view  
    14.                 ViewData["uploaderhtml"] = uploader.Render();  
    15.                 //if it's HTTP POST:  
    16.                 if (!string.IsNullOrEmpty(myuploader))  
    17.                 {  
    18.                     List<string> processedfiles = new List<string>();  
    19.                     //for multiple files , the value is string : guid/guid/guid   
    20.                     foreach (string strguid in myuploader.Split('/'))  
    21.                     {  
    22.                         Guid fileguid = new Guid(strguid);  
    23.                         CuteWebUI.MvcUploadFile file = uploader.GetUploadedFile(fileguid);  
    24.                         if (file != null)  
    25.                         {  
    26.                             //you should validate it here:  
    27.                             //now the file is in temporary directory, you need move it to target location  
    28.                             //file.MoveTo("~/myfolder/" + file.FileName);  
    29.                             processedfiles.Add(file.FileName);  
    30.                         }  
    31.                     }  
    32.                     if (processedfiles.Count > 0)  
    33.                     {  
    34.                         ViewData["UploadedMessage"] = string.Join(",", processedfiles.ToArray()) + " have been processed.";  
    35.                     }  
    36.                 }  
    37.             }  
    38.             return View();  
    39.         }  
     

    Regards,

     

    Ken 

View Complete Thread