1

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);
}
4

1 回答 1

2

Remove the [] from the name:

<input type="file" name="files">
<input type="file" name="files">
于 2012-05-24T11:31:13.370 回答