Is it possible to specify Jquery File Upload to post back only once (for multiple files)?
Posted
by
JaJ
on Stack Overflow
See other posts from Stack Overflow
or by JaJ
Published on 2012-04-03T23:25:27Z
Indexed on
2012/04/03
23:29 UTC
Read the original article
Hit count: 231
When I upload multiple files (per bluimp jquery file upload) the [httppost] action is entered once per file. Is it possible to specify one and only one postback with an enumerated file container to iterate?
View:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script src="@Url.Content("~/Scripts/jquery.ui.widget.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.iframe-transport.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.fileupload.js")" type="text/javascript"></script>
<input id="fileupload" type="file" name="files" multiple="multiple"/>
Controller:
public ActionResult Index()
{
return View();
}
[HttpPost]
public ActionResult Index(IEnumerable<HttpPostedFileBase> files)
{
// This is posted back for every file that gets uploaded...I would prefer it only post back once
// with a actual collection of files to iterate.
foreach (var file in files) // There is only ever one file in files
{
var filename = Path.Combine(Server.MapPath("~/App_Data"), file.FileName);
file.SaveAs(filename);
}
return View();
}
© Stack Overflow or respective owner