This article mainly introduces the materials related to the file upload function implemented by the JQueryfileupload plug-in. For more information, see. net MVC.
1. Create a Model class
Using System; using System. Collections. Generic; using System. Linq; using System. Web; namespace RCRS. WebApp. LG. EM. Models {// templates {//----------------------------------------------------------------////// Use the Import image ///// ------------------------------------------------------------------ Public class tmp_UploadFile {///Public HttpPostedFileBase FileName {get; set ;}}}
2. The corresponding method in the actual controller is complicated and I am too lazy to modify the processing logic.
//----------------------------------------------------------------////// Please wait until then //////
// ---------------------------------------------------------------- [HttpPost] public virtual ActionResult UploadFile () {HttpPostedFileBase uploadedFile = Request. files ["FileName"]; string message = "too many attempts have been made. Too many failed attempts have been made. "; Bool isUploaded = false; string path =" "; string dateTimeNow = DateTime. now. toString ("yyMMdd-hhmmss"); string userName = User. identity. getUserName (); string uploadMsg = string. empty; if (uploadedFile! = Null & uploadedFile. ContentLength! = 0) {string pathForSaving = Server. MapPath ("~ /App_Data/Uploaded/"); try {if (BsnssBihin. isExcel (uploadedFile. fileName) {path = System. IO. path. combine (pathForSaving, dateTimeNow + "_" + uploadedFile. fileName); uploadedFile. saveAs (path); isUploaded = BsnssBihin. uploadBihinChange (path, userName, ref uploadMsg); if (isUploaded) {message = "too many bytes have been uploaded successfully completed successfully! "+" \ N "+ uploadMsg; Logger. info ("[succeeded] latest product has been successfully installed," + dateTimeNow + ", "+" ["+ userName +"] "+" ["+ path +"] "+ uploadMsg );} else {message = "too many failed attempts when there is a loss of bandwidth when there are too many attempts. "+" \ N "+ uploadMsg; Logger. info ("[MISSING] latest products available soon," + dateTimeNow + ", "+" ["+ userName +"] "+" ["+ path +"] "+ uploadMsg );}} else {message = "too many errors in the form of too many errors. ";}} Catch (Exception ex) {message = string. format ("missing bytes have failed: {0}", ex. message); Logger. info ("[lost] failed product warning:" + ex. message + dateTimeNow + "," + "[" + userName + "]" + "[" + path + "]") ;}} return Json (new {isUploaded = isUploaded, message = message}, "text/html ");}
3. Page Installation
@ Model RCRS. WebApp. LG. EM. Models. tmp_UploadFile
| |
Select @ Html. textBoxFor (m => m. fileName, new {id = "file-upload", type = "file", accept = "application/vnd. openxmlformats-officedocument.spreadsheetml.sheet, application/vnd. ms-excel "}) |
There are already too many other |
Currently, the number of requests to be processed is low.
@ Section scripts {@ Scripts. Render ("~ /Bundles/jquery ") @ Scripts. Render ("~ /Bundles/jqueryui ") @ Scripts. Render ("~ /Bundles/jqueryval ") @ Scripts. Render ("~ /Bundles/common ") @ Scripts. Render ("~ /Bundles/fileupload ")