文件输入空,但空"文件"在Request.Files显示出来 [英] File input empty but an empty "file" shows up in Request.Files

查看:201
本文介绍了文件输入空,但空"文件"在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 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆