【发布时间】:2014-04-09 01:11:40
【问题描述】:
I want to upload a file without using the submit button. The file must be uploaded at the moment the user picks it from browse file window.
现在请提供一些 ajax 代码或一些 jquery 来上传文件以及如何删除文件。
Please provide the control view for this.
View>>>
<form action="FileUploadPost" method="post" enctype="multipart/form-data">
<label for="file1">Filename1:</label>
<input type="file" name="files" id="file3" />
<label for="file2">Filename2:</label>
<input type="file" name="files" id="file4" />
</form>
控制器>>>
[HttpPost]
public ActionResult Index(IEnumerable<HttpPostedFileBase> files)
{
foreach (var file in files)
{
if (file.ContentLength > 0)
{
var fileName = Path.GetFileName(file.FileName);
var path = Path.Combine(HttpContext.Server.MapPath("~/App_Data/Uploads"), fileName);
file.SaveAs(path);
}
}
return RedirectToAction("Index");
}
【问题讨论】:
标签: javascript jquery asp.net-mvc asp.net-mvc-4 file-upload