所以,我尝试按照这里的解决方案:
Dropzone image upload options not working :(
但是,每当我提供选项时:
Dropzone.autoDiscover = false;
dropzone从使用"浏览"显示默认拖动&n;' drop look到文本。按钮。
这是我的代码(dropzone包含在标题中):
<script type="text/javascript">
$(document).ready(function () {
Dropzone.autoDiscover = false;
$("#uploadme").dropzone({
maxFilesize: 5000,
dictDefaultMessage: "Drop your file here to upload (multiple files require being zipped)",
uploadMultiple: false,
addRemoveLinks: true
});
});
</script>
<h5>Test space for FTP</h5>
<asp:Label ID="lblError" runat="server"></asp:Label>
<div class="mainContent">
<form runat="server" method="post" enctype="multipart/form-data"
class="dropzone"
id="ftpUpload">
<div class="fallback" id="uploadme">
<input type="file" name="file" multiple />
<input type="submit" value="Upload" />
</div>
</form>
</div>
所以,问题是,如何在不破坏默认外观的情况下为dropzone指定选项?
答案 0 :(得分:7)
祝你好运
@{
}
<div id="dropzone">
<form action="/Photo/Upload" class="dropzone" id="uploader" enctype="multipart/form-data"></form>
</div>
@section Styles{
<link rel="stylesheet" type="text/css" href="~/lib/dropzone/dist/basic.css" />
<link rel="stylesheet" type="text/css" href="~/lib/dropzone/dist/dropzone.css" />
}
@section Scripts{
<script src="~/lib/dropzone/dist/dropzone.js"></script>
<script>
Dropzone.autoDiscover = false;
window.onload = function () {
var dropzoneOptions = {
dictDefaultMessage: 'Drop Here!',
paramName: "file",
maxFilesize: 2, // MB
addRemoveLinks: true,
init: function () {
this.on("success", function (file) {
console.log("success > " + file.name);
});
}
};
var uploader = document.querySelector('#uploader');
var newDropzone = new Dropzone(uploader, dropzoneOptions);
console.log("Loaded");
};
</script>
}
答案 1 :(得分:2)
我自己想通了。我是ASP.NET Web Forms的新手,忘了Javascript是客户端,因此引用了客户端与服务器端不同的元素ID。我查看了源代码并发现表单的ID是“aspnetForm”,因此我将选项代码更改为:
Dropzone.options.aspnetForm = {
uploadMultiple: false,
maxFiles: 1,
maxFilesize: 5000,
等
现在有效!
答案 2 :(得分:0)
四个选项:
.dropzone
,以便自动发现不会使用它。如果您想使用默认的CSS,这会让您感到困惑Dropzone.autoDiscover = false;
document.querySelector(formname).dropzone.options
Dropzone.instances[0].options
如果您使用后面的步骤(如其网站所建议),则还可以设置元素上的URL之类的选项,并通过以下方式合并这些选项:
let dz = document.querySelector(formname).dropzone
dz.options = { ...dz.options, ...{ myopts } }