I need some help. I'm trying to upload files using <input type="file">
. Here is my View:
@using (Html.BeginForm("BookAdd", "Admin", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<input type="file" name="files[0]" id="files[0]" />
<input type="file" name="files[1]" id="files[1]" />
<input type="submit" value="Upload Book" />
}
And here is an Action which should process uploaded file.
[HttpPost]
public ActionResult BookAdd(IEnumerable<HttpPostedFileBase> files)
{
// some actions
return View();
}
The problem is that "files" always contains two elements which are null.
What can be done to fix it?
It's time for some news. It seems like I found the problem, but I still don't know how to fix it. It appears that despite the fact I'm using "multipart/form-data" here:
@using (Html.BeginForm("BookAdd", "Admin", FormMethod.Post, new { enctype="multipart/form-data" }))
{
<input type="file" name="File" id="file1" />
<input type="file" name="File" id="file2" />
<input type="submit" value="Upload Book" />
}
Request.ContentType
remains "application/x-www-forum-urlencoded" in controller..
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…