The JQuery fileupload plug-in implements the file upload function, jqueryfileupload
The truth is the same. I will share with you the actual installation in. 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 {// examples /// <summary> // Import image // </summary> // implements public class tmp_UploadFile {/// <summary> </summary>> 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.
// Configure /// <summary> /// specify valid values when creating a snapshot // </summary> /// <returns> </returns> // configure [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 <table align = "center" style = "margin-bottom: 200px"> <tr> <td> <div style = "width: 470px "> <input type =" text "id =" tbx-file-path "value =" too many bytes selected when they have been selected before "readonly =" readonly "/> </div> </td> <div style =" width: 60px "> <span class =" btn-primary fileinput-button "> <span> optional values </span> @ Html. textBoxFor (m => m. fileName, new {id = "file-upload", type = "file", Ccept = "application/vnd. openxmlformats-officedocument.spreadsheetml.sheet, application/vnd. ms-excel "}) </span> </div> </td> <div style =" width: 60px "> <a class =" btn-primary "href =" # "id =" hl-start-upload "> too many concurrent upload attempts </a> </ div> </td> </tr> </table> <div id = "loadingOver" class = "loadingOver"> </div> <div id = "dvloader" class = "dvloader"> <span class = "label-info" style = "align-content: center "> checking, <Br/> </div> @ section scripts {@ Scripts. render ("~ /Bundles/jquery ") @ Scripts. Render ("~ /Bundles/jqueryui ") @ Scripts. Render ("~ /Bundles/jqueryval ") @ Scripts. Render ("~ /Bundles/common ") @ Scripts. Render ("~ /Bundles/fileupload ") <script type =" text/javascript "> var data_upload; $ (document ). ready (function () {'use strict '; $ (' # file-upload '). fileupload ({url :'.. /Bihin/UploadFile ', dataType: 'json', add: function (e, data) {data_upload = data ;}, done: function (event, data) {if (data. result. isUploaded) {$ ("# tbx-file-path "). val ("zookeeper"); data_upload = "" ;}$ ("# dvloader" ).css ("display ", "none"); $ ("# loadingOver" cmd.css ("display", "none"); alert (data. result. message) ;}, fail: function (event, data) {data_upload = ""; if (data. files [0]. error) {$ ("# dvloader" ).css ("display", "none"); $ ("# loadingOver" ).css ("display", "none "); alert (data. files [0]. error) ;}}}) ;}); $ ("# hl-start-upload "). on ('click', function () {if (data_upload) {$ ("# dvloader" ).css ("display", "block "); $ ("# loadingOver" ).css ("display", "block"); data_upload.submit () ;}return false ;}); $ ("# file-upload "). on ('change', function () {$ ("# tbx-file-path "). val (this. files [0]. name) ;}); </script>}
√. That's what it looks like.
A simple loding implementation is also provided.
Paste the CSS code:
.dvloader { display:none; position:absolute; top:40%; left:40%; width:20%; height:20%; z-index:1001; text-align:center; font-size:1.5em;}.loadingOver { display:none; position:absolute; top:0; left:0; width:100%; height:100%; background-color:#f5f5f5; opacity:0.5; z-index:1000;}
Here, let's talk about it:
For the accept attribute of input, only the Excel file is read here, so
APP/vnd. openxmlformats-officedocument.spreadsheetml.sheet, application/vnd. ms-excel
The above is all the content of this article, hoping to help you learn.
Articles you may be interested in:
- Jquery-ajaxfileupload asynchronous upload plug-in (with Engineering Code)
- How to add additional parameters to jquery's ajaxfileupload
- Example of asynchronous file upload using jquery uploadify and apache Fileupload
- An example of a simple jQuery plug-in ajaxfileupload. js to implement ajax File Upload
- Two jQuery plug-ins -- jquery. fileupload and artdialog
- JQuery plugin ajaxFileUpload implements asynchronous file upload
- JQuery plug-in ajaxfileupload. js uploads files asynchronously to an instance.
- JQuery asynchronous file upload plug-in ajaxFileUpload details
- PHP uses the jQuery plug-in ajaxFileUpload to Implement Asynchronous file upload.