Reputation: 2244
I'm trying to upload multiple files, the dialog shows multiple files selected (pictured below), but only the first file gets stored in my code. What am I doing wrong?
@Html.TextBoxFor(model => model.files, new { @class = "form-control", type = "file", multiple = "true", placeholder = "upload files"})
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Create([Bind(Include = "type,files,date")] Task mydata)
{
System.Diagnostics.Debug.Write(mydata.files);//outputs: "C:\<path>\asdf.txt"
}
Edit: Task.files is of type string
Upvotes: 1
Views: 549
Reputation: 24222
When uploading multiple files, you want to bind to a collection. IEnumerable<string>
should give you all filenames.
However, when uploading a file, the property should be a HttpPostedFileBase
. When uploading multiple files, you need IEnumerable<HttpPostedFileBase>
.
Upvotes: 2