多文件上传使用单个文件标签 [英] multiple files upload using single file tag
问题描述
我看到每个人都很多帖子是用这种方法
<形式的行动=方法=POSTENCTYPE =的multipart / form-data的>
<输入类型=文件名称=文件ID =文件1/>
<输入类型=文件名称=文件ID =文件2/>
<输入类型=提交/>
< /表及GT;
然后在控制器中使用
[HttpPost]
公众的ActionResult上传(IEnumerable的< HttpPostedFileBase>文件)
{
的foreach(在文件var文件)
{
file.SaveAs(mypath中);
}
返回RedirectToAction(「指数」);
}
我试过,并成功这种方式。但是,当我做到这一点。
<形式的行动=方法=POSTENCTYPE =的multipart / form-data的>
<输入类型=文件名称=文件ID =文件多/>
<输入类型=提交/>
< /表及GT;
这个选择多个文件,在客户结束,但如果我用同样的上述(控制器)$ C $在控制器C,我能够只上传一个文件。
什么反刍是解决方案(控制器code )如果我想,以方便用户选择,一旦所有所需的图像(假设他/有他们在同一个文件夹/目录)是指采用单文件标记。不像(这许多文章)
的http://www.$c$cproject.com/Articles/442515/Uploading-and-returning-files-in-ASP-NET-MVC
http://haacked.com/archive /2010/07/16/uploading-files-with-aspnetmvc.aspx/
和
的http://demos.devex$p$pss.com/MVCxFileManagerAndUploadDemos/UploadControl/MultiFileUpload
[HttpPost]
公众的ActionResult上传()
{
的foreach(在Request.Files var文件)
{
file.SaveAs(mypath中);
}
返回RedirectToAction(「指数」);
}
I Have seen many posts about everyone is using this approach
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="files" id="file1" />
<input type="file" name="files" id="file2" />
<input type="submit" />
</form>
And then in controller the use
[HttpPost]
public ActionResult Upload(IEnumerable<HttpPostedFileBase> files)
{
foreach(var file in files)
{
file.SaveAs("myPath");
}
return RedirectToAction("Index");
}
I tried and succeeded this way. But when I do it with
<form action="" method="post" enctype="multipart/form-data">
<input type="file" name="files" id="file" multiple />
<input type="submit" />
</form>
This selects multiple files at the client end but If I use the same above(controller's) code in controller., I am able to upload only one file.
What cud be the solution (the controller code) If I want to facilitate user to select all desired image once (suppose he/has them in same folder/directory) means using single file tag. Unlike (these many articles)
http://www.codeproject.com/Articles/442515/Uploading-and-returning-files-in-ASP-NET-MVC
http://haacked.com/archive/2010/07/16/uploading-files-with-aspnetmvc.aspx/
and http://demos.devexpress.com/MVCxFileManagerAndUploadDemos/UploadControl/MultiFileUpload
[HttpPost]
public ActionResult Upload()
{
foreach(var file in Request.Files)
{
file.SaveAs("myPath");
}
return RedirectToAction("Index");
}
这篇关于多文件上传使用单个文件标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!