form表单一次上传多种类型的图片(每种类型的图片可以上传多张)
controller中的action方法
public ActionResult UploadImage( ){ int imageType=(int)Request.Form["ImageType"]; //整体图片集合 IListwholePictureIList = Request.Files.GetMultiple("WholePicture");//HttpPostedFileBase:充当类的基类,这些类提供对客户端上传的文件的单独访问;Request.Files.GetMultiple(string name):返回与name匹配的所有文件 //周边图片集合 IList AroundSupportPictureIList = Request.Files.GetMultiple("AroundSupportPicture"); if (wholePictureIList[0].FileName != "") { foreach (var item in wholePictureIList) { byte[] b = new byte[item.ContentLength]; item.InputStream.Read(b, 0, item.ContentLength); model.WholePicture.Add(b);//model.WholePicture是byte[]的集合,即图片的流文件,可以存到数据库中 } } if (AroundSupportPictureIList[0].FileName != "") { foreach (var item in AroundSupportPictureIList) { byte[] b = new byte[item.ContentLength]; item.InputStream.Read(b, 0, item.ContentLength); model.AroundSupportPicture.Add(b); } } int userId = (int)Session["UserId"]; ManageParkPediaService service = new ManageParkPediaService(); StateInfo infoT = service.SaveImage(model, userId); return Json(infoT);}
view中的代码
引入<script src="~/Scripts/jquery.form.js"></script>