我已經在我的項目中實現了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,
});
});
但是但我仍然得到錯誤。
我試過這個,並用新的Jquery更新了我的問題,但我仍然得到錯誤?!?!我已經把你的建議上面我的執行Dropzone – 2014-12-06 06:12:08
夥計它的完美....我得到了答案。 – 2015-09-11 08:54:02