我已经在我的项目中实现了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