基於asp.net MVC的無重新整理檔案上傳

來源:互聯網
上載者:User
Code
 1 <div style="float:left;">
 2         <div style="position: absolute; z-index: -1; background-color: Gray; height: 25px;
 3             line-height: 25px; width: 68px; text-align:center; color:White; cursor:pointer;">
 4             添加檔案
 5         </div>
 6         <div style="height: 25px; width: 68px;line-height: 25px;cursor:pointer;">
 7             <input type="file" id="File1" name="File1" style="line-height: 25px; background-color: Red;
 8                 height: 25px; width: 68px; filter: Alpha(opacity=0); -moz-opacity: 0.0; opacity: 0.0;
 9                 z-index: 1; cursor:pointer;" onchange="text.value=this.value;" />
10         </div>
11     </div>
12     
13     <input type="text" id="text" style="height:24px; line-height:24px; background-color:Gray; color:White;"/>
14     <input type="button" onclick="upload_Click();" value="上傳" style="height:25px; line-height:25px;"/>
15 
16     
17     <div style="display:none; position:absolute; top:0; left:0;">
18         <iframe name="uploadResponse"></iframe>
19         <% using (Html.BeginForm("upload", "AQ", FormMethod.Post, new { enctype = "multipart/form-data", target = "uploadResponse", id = "load" }))
20            {%>
21         <%} %>
22     </div>
23 
24     <script type="text/javascript">
25         function upload_Click() {
26             var imgObj = document.getElementById("File1");
27             var from1 = document.getElementById("load");
28             from1.appendChild(imgObj);
29             from1.submit();
30         }
31         function ss() {
32             alert("上傳成功");
33         }
34 </script>Code
 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Web;
 5 using System.Web.Mvc;
 6 using System.Web.Mvc.Ajax;
 7 using Medusa.Mow.BusinessRule;
 8 using Medusa.Mow.DataModel;
 9 namespace MedusaOfficialWeb.Controllers
10 {
11     [HandleError]
12     public class AQController : PageController
13     {
14         public ActionResult Index()
15         {
16             return View();
17         }
18 
19         public string upload()
20         {
21             HttpFileCollectionBase files = HttpContext.Request.Files;
22             for (int iFile = 0; iFile < files.Count; iFile++)
23             {
24                 HttpPostedFileBase postedFile = files[iFile];
25                 string fileName = System.IO.Path.GetFileName(postedFile.FileName);
26                 if (fileName != null && fileName != string.Empty)
27                 {
28                     postedFile.SaveAs(Server.MapPath("~/file/" + DateTime.Now.Ticks.ToString() + fileName));
29                 }
30             }
31 
32             Response.Write(string.Format("<script type='text/javascript'>window.parent.ss();</script>"));
33             return string.Empty;
34         }
35     }
36 }
37 
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.