繁体   English   中英

当dropzone整合到表单中时,表单提交两次

[英]form submit twice when dropzone integrated in form

我在表单中使用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.
        });

感谢阅读,也许对我有帮助:-)

试试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
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM