在局部视图上设置dropzone的正确方法是什么?

时间:2015-12-15 16:44:40

标签: javascript html asp.net-mvc-4 dropzone.js

我试图在局部视图上设置一个dropzone但是从不触发init()函数。我在父视图上放置了完全相同的dropzone并且它正常工作。是什么导致它在父视图上正常工作而在子视图/部分视图上没有?任何帮助都会非常感激,因为我已经在这个问题上停留了一段时间。

<div class="dropzone" id="dropzoneForm">
        <div class="fallback">
            <input name="file" type="file" multiple />
            <input type="button" value="Upload" class="k-button" />
        </div>
    </div>


<script>

Dropzone.autoDiscover = true;

    Dropzone.options.dropzoneForm = {

        init: function () {

            alert("init");

            this.on("complete", function (data) {
                //var res = eval('(' + data.xhr.responseText + ')');
                var res = JSON.parse(data.xhr.responseText);

                if (this.getQueuedFiles().length == 0) {
                    alert("Image was uploaded successfully."); //Success Message
                }

            });
        },

        url: '@Url.Action("SaveFormImage", "Project")' + "?projID=" + '@projectID',
        paramName: "file",
        uploadMultiple: false,
        fileSizeBase: 1024,
        parallelUploads: 1,

        maxFiles: 1,
        maxFilesize: 1000,
        acceptedFiles: ".jpeg, .pdf, .bmp, .jpg, .png",
        addRemoveLinks: false,
        createImageThumbnails: false,
        dictDefaultMessage: "Drop Image Here or Click to Upload",
        //autoProcessQueue: false,
    };

1 个答案:

答案 0 :(得分:0)

我不确定你是否还在寻找这个,但你可以在javascript中触发dropzone:

var myDropzone = new Dropzone("div#myId", { url: "/file/post"});

或JQuery:

    $("div#myId").dropzone({ url: "/file/post" });

来源:Dropzone

致以最诚挚的问候,

Nenos