複数のファイルを (blueimp jquery ファイルのアップロードごとに) アップロードすると、[httppost] アクションがファイルごとに 1 回入力されます。反復する列挙型ファイル コンテナーを使用して、ポストバックを 1 つだけ指定することは可能ですか?
意見:
<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"/>
コントローラ:
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 collection of files to iterate. Is this possible?
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();
}