The JQueryfileupload plug-in implements the file upload function _ jquery

Source: Internet
Author: User
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 ")

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.