我正在尝试在ASP.NET MVC中上传多个文件,我在我的控制器中有这个简单的foreach循环
foreach (HttpPostedFileBase f in Request.Files)
{
if (f.ContentLength > 0)
FileUpload(f);
}
Run Code Online (Sandbox Code Playgroud)
以前的代码生成此错误:
Unable to cast object of type 'System.String' to type 'System.Web.HttpPostedFile'.
Run Code Online (Sandbox Code Playgroud)
我不明白的是为什么Request.Files [1]返回一个HttpPostedFileBase但是当迭代它时,它返回字符串(可能是文件名).
注意:我知道这可以用for循环解决.此外,我尝试使用HttpPostedFile,同样的错误.