我在表单中使用dropzone。表单已包含字段。当用户提交表单时,指向表单的操作(在我的情况下是控制器)被调用两次:第一次使用dropzone文件,第二次没有文件,为什么?如何防止第二次重新发布同一表格?
以下是我所做的:
HTML:
@using (Html.BeginForm("Create", "Home", FormMethod.Post, new { enctype = "multipart/form-data", @class = "dropzone", id = "myForm" }))
{
... some fields...
<div class="fallback">
<!-- this is the fallback if JS isn't working -->
<input name="files" type="file" multiple />
</div>
... submit button ...
}
JS:
// autodiscover at false otherwise, dropzone will attach twice
Dropzone.autoDiscover = false;
var myDropzone = new Dropzone('#myForm', {
paramName: 'files',
autoProcessQueue: false,
uploadMultiple: true,
parallelUploads: 25,
maxFiles: 25
});
$("form").on("submit", function (event) {
myDropzone.processQueue(); // Tell Dropzone to process all queued files.
});
感谢阅读并可能帮助我: - )
答案 0 :(得分:0)
尝试jQuery .one()这样可以确保表单只提交一次。
$("form").one("submit", function (event) {
event.preventDefault();
myDropzone.processQueue(); // Tell Dropzone to process all queued files.
window.location.href = "Index.aspx"; //Specify the file name and path
});