【发布时间】:2012-02-29 14:04:33
【问题描述】:
我创建了一个保存文件的控制器。
以下代码是该控制器的一部分:
if ( Request.Files.Count != 0 ) {
HttpFileCollectionBase files = Request.Files;
foreach ( HttpPostedFileBase file in files ) {
if ( file.ContentLength > 0 ) {
if ( !file.ContentType.Equals( "image/vnd.dwg" ) ) {
return RedirectToAction( "List" );
}
}
}
}
在 ASPX 页面中很简单:
<input type="file" name="file" />
<input type="file" name="file" />
...// many inputs type file
问题是foreach,因为它返回类似的错误(我知道是因为我在调试模式下运行并在 foreach 语句中放置了断点):
Unable to cast object of type 'System.String' to type 'System.Web.HttpPostedFileBase'.
我的错误是什么?
【问题讨论】:
标签: c# asp.net asp.net-mvc-3