DotNet 笔记

东方欲晓,莫道君起早。

ASP.NET MVC 图片上传(最基本的例子)

Html表单

<body>
    <div>
        <form action="/home/uploadimg" method="post" enctype="multipart/form-data">
            <input  type="file" name="file1" />
            <input  type="submit" value="submit" />
        </form>
    </div>
</body>

处理程序:

 public class HomeController : Controller
    {

        public ActionResult Index()
        {
            return View();
        }

        [HttpPost]
        public ActionResult UploadImg()
        {
            if (Request.Files.Count > 0)
            {
                HttpPostedFileBase f =Request.Files["file1"];
                f.SaveAs(@"D:\" + f.FileName);
            }
            return View();
        }

    }

 

Loading