VIEW 代码

@using (Html.BeginForm("Upload", "UploadFile", FormMethod.Post, new { enctype = "multipart/form-data" }))

{   

 <input type="file" name="file" />   

 <input type="submit" value="OK" />

 }

 

Controller 代码

          [HttpPost]        

 public ActionResult Upload(HttpPostedFileBase file)      

 {            

        if (file != null && file.ContentLength > 0)    

            {           

               // extract only the fielname                 

               var fileName = Path.GetFileName(file.FileName);       

              // store the file inside ~/App_Data/uploads folder             

              var path = Path.Combine(Server.MapPath("~/Content/File"), fileName);    

               file.SaveAs(path);                

         }             

         // redirect back to the index action to show the form once again         

         return RedirectToAction("Index");     

 }

 

 

相关文章:

  • 2021-11-03
  • 2021-07-14
  • 2021-12-26
  • 2021-10-17
猜你喜欢
  • 2022-03-03
  • 2018-05-21
  • 2021-10-25
  • 2021-05-10
  • 2021-04-22
  • 2021-06-30
相关资源
相似解决方案