在ASP.NET MVC中上传多个文件 [英] Multiple File Upload in asp.net mvc
本文介绍了在ASP.NET MVC中上传多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要从同一个表格中的单个文件上传器和多个文件上传器中获取文件.并且还需要知道这些文件来自哪个输入字段. 我可以从Request.Files获取所有文件,但不知道这些文件来自哪个字段.
I need to get files from a single file uploader and a multiple file uploader from the same form. And also need to know from which input field those files are coming. From Request.Files i can get all files but can't know from which field those file are coming.
我有一张表格.
<form>
<input type="file" name="file1">
<input type="file" name="files" multiple="true">
</form>`
推荐答案
直接使用模型代替Request.Files
.根据您的视图,您可以执行以下操作:
Use a model instead of Request.Files
directly. Based off your view you could do something like this:
public class UploadForm
{
public HttpPostedFileBase file1 {get;set;}
public IEnumerable<HttpPostedFileBase> files {get;set;}
}
然后执行操作:
public ActionResult Uploade(UploadForm form)
{
if(form.file1 != null)
{
//handle file
}
foreach(var file in form.files)
{
if(file != null)
{
//handle file
}
}
...
}
这篇关于在ASP.NET MVC中上传多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文