基於MVC uploadify 3.2 Jquery外掛程式介紹 及簡單應用

來源:互聯網
上載者:User

鼓搗了差不多一天的 uploadify 3.2 不知道這是什麼的去百度下,然後下載,簡單介紹下這是一款Jquery外掛程式,提供了美觀的介面和易操作性。

看代碼:

 1 @{ 2     ViewBag.Title = "Index"; 3 } 4 <script src="http://www.cnblogs.com/Scripts/jquery-1.5.1.min.js" type="text/javascript"></script> 5 <script src="http://www.cnblogs.com/Scripts/uploadify-v3.2/jquery.uploadify.js" type="text/javascript"></script> 6 <script src="http://www.cnblogs.com/Scripts/uploadify-v3.2/jquery.uploadify.min.js" type="text/javascript"></script> 7 <link href="http://www.cnblogs.com/Scripts/uploadify-v3.2/uploadify.css" rel="stylesheet" type="text/css" /> 8 <h2>Index</h2> 9 10 <script type="text/javascript" language="javascript">11     $(document).ready(function () {12         $("#MyUpload").uploadify({13         'swf':"/Scripts/uploadify-v3.2/uploadify.swf",14         'uploader': '/Home/Upload',15         'auto':true16     });17 18 });19 </script>20 21 <input type="file" id="MyUpload" name="myUploadd" />

簡潔通俗的代碼 才是我喜歡的,介紹不詳細勿噴。

看後台:

 1         public ActionResult Index() 2         { 3             return View(); 4         } 5         [AcceptVerbs(HttpVerbs.Post)] 6         public ContentResult Upload(HttpPostedFileBase FileData) 7         { 8             string filename = ""; 9             if (null != FileData)10             {11                 try12                 {13                     filename = Path.GetFileName(FileData.FileName);//獲得檔案名稱14                     15                     saveFile(FileData, filename);16                 }17                 catch (Exception ex)18                 {19                     filename = ex.ToString();20                 }21             }22             return Content(filename);23         }24 25         [NonAction]26         private bool saveFile(HttpPostedFileBase postedFile,string saveName)27         {28             bool result = false;29 30             string path = Server.MapPath(@"~/Logs/") + saveName;31             try32             {33                 postedFile.SaveAs(path);//Path.Combine(filepath, saveName)34                 result = true;35             }36             catch (Exception e)37             {38                 throw new ApplicationException(e.Message);39             }40             return result;41         }42  43     }

好,代碼貼完。這個是能用的,簡單有效

現在來介紹戲常用的,如果想知道更多,就參考官方doc:

uploader 用於通訊後台方法,你懂的
swf    進度條動畫,下載包裡面內建了
auto 點擊選擇檔案之後是否自動上傳
buttonText 選擇按鈕的文字
height,width 按鈕的高寬  
debug 這個是顯示調試
method 這個你也可以選擇,不過預設就是Post了,你可以改get
fileTypeExts 這是上傳檔案的類型,
fileSizeLimit 檔案大小設定0 為不限制
multi 是否選擇多個檔案
queueSizeLimit 隊列中的最大檔案項目  
postData: {}

和後台互動時,附加的參數

 

 

 

 

 

 

 

 

 

湊合著用吧。

o(∩_∩)o

到此,下回見,下次寫點基礎的。表驅動法,新手必備哦。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.