Why do I have error when I use IEnumerable filebase?
I use this code
@using (Html.BeginForm("Create", "Album", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<h4>AlbumViewModel</h4>
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
<div class="form-group">
@Html.LabelFor(model => model.Name, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Name, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Name, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Toltip, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.Toltip, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.Toltip, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Imageurl1, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
<input type="file" name="Files" value=" " id="File1" />
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Imageurl2, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
<input type="file" name="Files" value=" " id="File2" />
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.Imageurl3, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
<input type="file" name="Files" value=" " id="File3" />
</div>
</div>`
and this code in Controller
[HttpPost]
public ActionResult Create(AlbumViewModel viewModel, IEnumerable<HttpPostedFileBase> files)
{
var file = files.ToList();
if (file[1].ContentLength>0)
{
viewModel.Imageurl1 = file[1].FileName;
}
if (file[2].ContentLength > 0)
{
viewModel.Imageurl2 = file[2].FileName;
}
if (file[3].ContentLength > 0)
{
viewModel.Imageurl3 = file[3].FileName;
}
return View();
}
but always I have error