最基本的实现方法:

视图:

 <% Html.BeginForm("Upload", "UploadTest", FormMethod.Post, new { enctype = "multipart/form-data" });
 %>
    <input type="file" name="fileLoad1" />
    <input type="submit" value="上传" />
 <% Html.EndForm(); %>

控制器:

[AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Upload(FormCollection formCollection)
        {
            int cnt=Request.Files.Count;
            if (cnt > 0)
            {
                string path = AppDomain.CurrentDomain.BaseDirectory + "uploads/";
                string filename = Path.GetFileName(Request.Files["fileLoad1"].FileName);
                Request.Files["fileLoad1"].SaveAs(Path.Combine(path, filename));
                string savename = "upload/" + filename;//这是要向数据库表中保存的数据
            }

            return View();
        }

 

网上牛人们还写了很多种方法,可以参考

 

 

相关文章:

  • 2021-10-20
  • 2021-05-27
  • 2021-11-24
  • 2022-12-23
  • 2022-12-23
  • 2021-11-06
  • 2021-09-11
  • 2022-02-23
猜你喜欢
  • 2022-01-03
  • 2022-12-23
  • 2022-01-06
  • 2021-11-01
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案