I created a controller that saves files.
The following code is part of this controller:
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" ); } } } }
on an aspx page is simple:
<input type="file" name="file" /> <input type="file" name="file" /> ...// many inputs type file
The problem is foreach because it returns an error (I know, because I run in debug mode and set a breakpoint in the foreach statement):
Unable to cast object of type 'System.String' to type 'System.Web.HttpPostedFileBase'.
What's my mistake?
source share