mvc中上传图片到指定文件夹中

前台:

1  @using (Html.BeginForm("AddImg", "UpFileImg", FormMethod.Post, new { enctype = "multipart/form-data" }))
2     {
3     <input type="file" name="file" />
4     <input type="submit" value="OK" />
5     }
one

后台:

 1  [HttpPost]
 2         public ActionResult AddImg(HttpPostedFileBase file)
 3         {
 4             if (file != null && file.ContentLength > 0) 
 5             {
 6           
 7                 var fileName =System.IO.Path.GetFileName(file.FileName);
 8                 var path = System.IO.Path.Combine(Server.MapPath("/img"), fileName);
 9                 file.SaveAs(path);
10             }
11             return Content("上传成功");
12         }
two
原文地址:https://www.cnblogs.com/angelgril/p/3143910.html