2014-12-05 144 views
1

我已經在我的項目中實現了dropzone,所有工作都很好。除非瀏覽器在頁面請求清晰時決定拋出一個錯誤我已經將視圖修剪得相當長,但下面的HTML當前存在於一個表單中(不知道是否會導致問題)我只有一個對dropzone的引用就是這裏顯示的,dropzone.js只包含在捆綁配置中的一次。Dropzone.js已經連接

錯誤:如果(this.element.dropzone)拋出新的錯誤( 「懸浮窗已連接」)

這是我的看法

<div class="form-group"> 
    <div class="col-xs-12 dropzone" id="UploadImage"> 
     <input type="file" id="id-input-file-2" /> 
    </div> 
</div> 

這是我如何創建懸浮窗

$(document).ready(function() { 

     $("div#UploadImage").dropzone({ url: '@Url.Action("SaveUploadedFile", "Person")' }); 
}); 

和我的控制器如下

public ActionResult SaveUploadedFile() 
    { 
     bool success = true; 

     string fName = string.Empty; 

     try 
     { 
      foreach (var file in Request.Files.Cast<string>().Select(fileName => Request.Files[fileName]).Where(file => file != null)) 
      { 
       fName = file.FileName; 

       if (file.ContentLength > 0) 
       { 
        // will write the rest of the code here 
       } 
      } 
     } 
     catch (Exception ex) 
     { 
      success = false; 
     } 

     return Json(success ? new { Message = fName } : new { Message = "Error in saving file" }); 
    } 

現在我能夠檢索控制器內的圖像,只是不確定代碼中的哪個地方會再次初始化dropzone,導致上述錯誤。

UPDATE

試圖戴夫斯建議我的jQuery後現在看起來是這樣

$(document).ready(function() { 

     Dropzone.options.myAwesomeDropzone = false; 

     $("div#UploadImage").dropzone({ 
      url: '@Url.Action("SaveUploadedFile", "Person")', 
      addRemoveLinks: true, 
      removedfile: function (file) { 
       var name = file.name; 
       $.ajax({ 
        type: 'POST', 
        url: '@Url.Action("DeleteUploadedFile", "Person")', 
        data: "id=" + name, 
        dataType: 'html' 
       }); 
       var ref; 
       return (ref = file.previewElement) != null ? ref.parentNode.removeChild(file.previewElement) : void 0; 
      }, 
      maxFilesize: 2, 
      maxFiles: 12, 

     }); 
}); 

但是但我仍然得到錯誤。

回答

1

嘗試從Reference here

  1. 關閉自動發現全局這樣的:Dropzone.autoDiscover = 假;,或

  2. 關閉自動發現這樣的特定元素的: Dropzone.options.myAwesomeDropzone = false;

+0

我試過這個,並用新的Jquery更新了我的問題,但我仍然得到錯誤?!?!我已經把你的建議上面我的執行Dropzone – 2014-12-06 06:12:08

+0

夥計它的完美....我得到了答案。 – 2015-09-11 08:54:02

0

從UploadImage元素的class屬性中刪除「dropzone」,錯誤將消失。我有同樣的問題,並修復它。

我想你通過自動發現設置爲false,並設置類的元素,給人的插件混合郵件「懸浮窗」。

0

這是唯一適用於我的解決方案。

我最終做的是將css類重命名爲「dropzone1」,然後在basic.cs和dropzone.cs文件中將「dropzone」的所有實例重命名爲「dropzone1」。這樣我保留了所有的CSS樣式。

一旦我做到了,它就像一個魅力。

相關問題