Reputation: 26501
I am posting multiple files to my controller but it does not seem to find them. It says that files
variable is null
. I can't understand where is the problem.
HTML
<form action="/gallery/create" enctype="multipart/form-data" method="post" novalidate="novalidate">
<div class="file-holder">
<div>
<input type="file" name="files[]">
<input type="file" name="files[]">
</div>
</div>
<input type="submit" value="Create">
</form>
Controller
[HttpPost]
public ActionResult Create(Gallery g, IEnumerable<HttpPostedFileBase> files)
{
string t = string.Empty;
foreach (var file in files)
{
t += file.FileName;
}
return Content(t);
}
Upvotes: 1
Views: 267
Reputation: 1038720
Remove the []
from the name:
<input type="file" name="files">
<input type="file" name="files">
Upvotes: 2