我有一个具有以下文件输入的 View :
<input type="file" name="SchemaFiles" id="SchemaFiles" class="form-control" multiple/>
我的模型有这个属性:
public List<HttpPostedFileBase> SchemaFiles { get; set; }
当我为此输入选择一两个文件时,一切正常。但是,如果我不选择任何文件并提交表单,则 SchemaFiles.Count
为 1
,SchemaFiles[0]
为 null
(但确实存在)。 ModelState.IsValid
为true
。
有办法避免这种情况吗?
最佳答案
这是设计使然,看起来根本原因是浏览器。 请参阅以下链接以供引用:
关于asp.net - 文件输入为空,但 Request.Files 中显示空的 "file",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34520301/