文件输入空,但空"文件"在Request.Files显示出来 [英] File input empty but an empty "file" shows up in Request.Files
本文介绍了文件输入空,但空"文件"在Request.Files显示出来的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个具有以下文件输入一个观点:
I have a view that has the following file input:
<input type="file" name="SchemaFiles" id="SchemaFiles" class="form-control" multiple/>
我的模型有这个属性:
My model has this attribute:
public List<HttpPostedFileBase> SchemaFiles { get; set; }
当我选择一个或两个文件,此输入,一切工作正常。但是,如果我不选择任何文件,并提交表单,那么 SchemaFiles.Count
是 1
和 SchemaFiles [0]
是空
(但确实存在)。 ModelState.IsValid
是真正
。
When I select one or two files for this input, everything works fine. However, if I don't select any files and submit the form, then SchemaFiles.Count
is 1
, and SchemaFiles[0]
is null
(but does exist). ModelState.IsValid
is true
.
有没有办法避免这种情况?
Is there a way to avoid this?
推荐答案
这是由设计,看起来像的根本原因是浏览器。
请参见以下链接供参考:
This is by-design and looks like the root cause is the browser. See these links for reference:
- ASP.NET工作项目: HTTP://aspnetwebstack.$c$cplex.com/工作项/ 188
- 文章#2:<一href=\"http://stackoverflow.com/questions/17614892/why-ienumerablehttppostedfilebase-count-is-1-when-i-upload-0-files\">Why IEnumerable的&LT; HttpPostedFileBase&GT;当我上传0文件?并计数1
- 博客文章:的http://michaelsync.net/2014/04/29/asp-net-mvc-multiple-files-upload-bug-or-by-design-issue
- ASP.NET work item: http://aspnetwebstack.codeplex.com/workitem/188
- Stackoverflow article: Why IEnumerable<HttpPostedFileBase> count is 1 when I upload 0 files? and
- Blog article: http://michaelsync.net/2014/04/29/asp-net-mvc-multiple-files-upload-bug-or-by-design-issue
这篇关于文件输入空,但空&QUOT;文件&QUOT;在Request.Files显示出来的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文