Live Support, Chat, Upload Control and Rich Text Editor
Welcome to Support forums Sign in | Join | Help |Client Center
in Search

ajax uploader in MVC

Last post 01-22-2013, 1:04 PM by Kenneth. 1 replies.
Sort Posts: Previous Next
  •  01-21-2013, 3:32 PM 76707

    ajax uploader in MVC


    Is is possible to avoid using "ashx"  file when implementing AjaxUploader in MVC. I would like  the uploader  to be an action method

    of my controller .


    thatnks for your help . 

  •  01-22-2013, 1:04 PM 76714 in reply to 76707

    Re: ajax uploader in MVC

    Hi amchiche,


    You can achieve it in the controllder directly. For example, in the selecting_multiole_files example.


    The red part will fire after uploaded. you can save/move/delete/change name in it. 


                public ActionResult selecting_multiple_files(string myuploader)
                      using (CuteWebUI.MvcUploader uploader = new CuteWebUI.MvcUploader(System.Web.HttpContext.Current))
                            uploader.UploadUrl = Response.ApplyAppPathModifier("~/UploadHandler.ashx");
                            //the data of the uploader will render as <input type='hidden' name='myuploader'> 
                            uploader.Name = "myuploader";
                            uploader.AllowedFileExtensions = "*.jpg,*.gif,*.png,*.bmp,*.zip,*.rar";
                            //allow select multiple files
                            uploader.MultipleFilesUpload = true;
                            //tell uploader attach a button
                            uploader.InsertButtonID = "uploadbutton";
                            //prepair html code for the view
                            ViewData["uploaderhtml"] = uploader.Render();
                            //if it's HTTP POST:
                            if (!string.IsNullOrEmpty(myuploader))
                                  List<string> processedfiles = new List<string>();
                                  //for multiple files , the value is string : guid/guid/guid 
                                  foreach (string strguid in myuploader.Split('/'))
                                        Guid fileguid = new Guid(strguid);
                                        CuteWebUI.MvcUploadFile file = uploader.GetUploadedFile(fileguid);
                                        if (file != null)
                                              //you should validate it here:
                                              //now the file is in temporary directory, you need move it to target location
                                              //file.MoveTo("~/myfolder/" + file.FileName);
                                  if (processedfiles.Count > 0)
                                        ViewData["UploadedMessage"] = string.Join(",", processedfiles.ToArray()) + " have been processed.";
                      return View();





View as RSS news feed in XML
Powered by ASP.Net
Copyright 2003 - 2017 CuteSoft Components Inc.. All rights reserved.