I am trying to upload multiple files on my web application. Hence I am using IEnumerable<HttpPostedFileBase> class to loop inside each file. But I am getting an error stating -
Error
System.Collections.Generic.IEnumerable<System.Web.HttpPostedFileBase>does not contain a definition for 'ContentLength' and no extension method 'ContentLength' accepting a first argument of typeSystem.Collections.Generic.IEnumerable<System.Web.HttpPostedFileBase' could be found (are you missing a using directive or an assembly reference?)
This error is for all the properties present in the HttpPostedFileBase class. I am trying to edit that class but it doesnt allow. I tried creating a IEnumerable of HttpPostedFileBase class in my ViewModel, but it fails again. What am I missing here?
Update - Code: View
<div class="col-sm-8">
<input type="file" name="Files" id="file1" class="form-control" />
<input type="file" name="Files" id="file2" class="form-control" />
<input type="submit" value="Save" class="btn btn-default" name="Command"/>
</div>
Controller
public ActionResult UploadFile(IEnumerable<HttpPostedFileBase> Files)
{
foreach (var item in Files)
{
if (Files != null && Files.ContentLength > 0)
{
FileUpload up = new FileUpload();
up.PersonId = model.PersonId;
up.FileName = System.IO.Path.GetFileName(Files.FileName);
up.MimeType = Files.ContentType;
up.FileContent = Files.Content;
bll.AddFileUpload(up);
}
}
return View();
}