欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

Mvc 上传图片

发布时间:2023/12/2 58 豆豆
生活随笔 收集整理的这篇文章主要介绍了 Mvc 上传图片 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

 

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");     

 }

 

 

转载于:https://www.cnblogs.com/a546558309/archive/2012/03/26/2417583.html

总结

以上是生活随笔为你收集整理的Mvc 上传图片的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。