用Html5与Asp.net MVC上传多个文件

html:

        <form action="/home/upload" method="post" enctype="multipart/form-data">
            <input type="file"  name="files" multiple/>
            <input type="submit" value="提交" />
        </form>

文件file 的name属性必填。

ActionResult:

 [HttpPost]
        public ActionResult Upload(HttpPostedFileBase[] files)
        {
            var path = Server.MapPath("/File");
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            foreach (HttpPostedFileBase item in files)
            {
                item.SaveAs(Path.Combine(path, item.FileName));
            }
            return Content("ok");
        }

H5让我们轻松实现文件上传.

猜你喜欢

转载自www.cnblogs.com/lunawzh/p/9326619.html
今日推荐