【问题标题】:Dropzone in div instead of entire formdiv中的Dropzone而不是整个表单
【发布时间】:2018-11-09 08:07:20
【问题描述】:

我正在按照本指南将 dropzone 集成到表单中并提交我的表单

https://github.com/enyo/dropzone/wiki/Combine-normal-form-with-Dropzone

然而,这就是我最终的结果

我的类别输入位于放置区域内部而不是外部。我的按钮也一样。如何让我的 dropzone 只位于一个 div 中而不是占据整个表单?

这是我的 dropzone 配置和表单

@section scripts{
    <script>
        $(document).ready(function () {
           $(document).on("submit", "#form", function (e) {
                e.preventDefault();
                $.ajax({
                    url: "@Url.Action("Save", @ViewContext.RouteData.Values["controller"].ToString())",
                    method: "POST",
                    processData: false,
                    contentType: false,
                    success: function (result) {
                        console.log(result);
                    }
                });
                return false;
            });
        });
    </script>
}
<div class="col-sm-12">
    <h2>Upload</h2>
    <hr />
</div>
@using (Html.BeginForm(null, null, FormMethod.Post,new { @class = "dropzone", enctype = "multipart/form-data", id = "form" }))
{
    @Html.AntiForgeryToken()
    <div class="col-sm-12">
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    @Html.LabelFor(m => m.Categories)
                    @Html.DropDownListFor(m => m.Categories, (SelectList)Model.Categories, "", new { @class = "form-control col-sm-12" })
                    @Html.ValidationMessageFor(m => m.Categories)
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="dropzone-previews form-group">
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <hr />
            </div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <div class="form-group">
                    <div class="clearfix">
                        <div class="pull-right">
                            <input type="submit" id="submit" value="Save" class="btn btn-primary" />
                            @Html.ActionLink("Cancel", "Index", @ViewContext.RouteData.Values["controller"].ToString(), new { }, new { @class = "btn btn-outline-secondary" })
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
}
<script>
    Dropzone.options.form = {
        autoProcessQueue: false,
        uploadMultiple: true,
        parallelUploads: 100,
        init: function () {
            var myDropzone = this;

            // First change the button to actually tell Dropzone to process the queue.
            this.element.querySelector("button[type=submit]").addEventListener("click", function (e) {
                // Make sure that the form isn't actually being sent.
                e.preventDefault();
                e.stopPropagation();
                myDropzone.processQueue();
            });
            // Listen to the sendingmultiple event. In this case, it's the sendingmultiple event instead
            // of the sending event because uploadMultiple is set to true.
            this.on("sendingmultiple", function () {
                // Gets triggered when the form is actually being sent.
                // Hide the success button or the complete form.
            });
            this.on("successmultiple", function (files, response) {
                // Gets triggered when the files have successfully been sent.
                // Redirect user or notify of success.
            });
            this.on("errormultiple", function (files, response) {
                // Gets triggered when there was an error sending the files.
                // Maybe show form again, and notify user of error
            });
        }
    };
</script>

【问题讨论】:

    标签: jquery asp.net asp.net-core dropzone.js


    【解决方案1】:

    在您的代码中尝试以下更改

    添加 'id="dropzonePreview"' 在你想要的

    <div class="col-sm-12">
                <div class="dropzone-previews form-group" id="dropzonePreview">
                </div>
    </div>
    

    在如下脚本中添加'previewpreviewsContainer: "#dropzonePreview", clickable: "#dropzonePreview"'

     Dropzone.options.form = {
            autoProcessQueue: false,
            uploadMultiple: true,
            parallelUploads: 100,
            previewpreviewsContainer: "#dropzonePreview",
            clickable: "#dropzonePreview",...}
    

    【讨论】:

      猜你喜欢
      • 2015-09-09
      • 1970-01-01
      • 2015-02-04
      • 1970-01-01
      • 2014-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多