jquery - div中的Dropzone而不是整个表单
问题描述
我正在按照本指南将 dropzone 集成到表单中并提交我的表单
https://github.com/enyo/dropzone/wiki/Combine-normal-form-with-Dropzone
然而,这就是我最终得到的
我的类别输入位于放置区域内部而不是外部。我的按钮也一样。如何让我的 dropzone 仅位于 div 中而不是占据整个表单?
这是我的 dropzone 配置和表单
@section scripts{
<script>
$(document).ready(function () {
$(document).on("submit", "#form", function (e) {
e.preventDefault();
$.ajax({
url: "@Url.Action("Save", @ViewContext.RouteData.Values["controller"].ToString())",
method: "POST",
processData: false,
contentType: false,
success: function (result) {
console.log(result);
}
});
return false;
});
});
</script>
}
<div class="col-sm-12">
<h2>Upload</h2>
<hr />
</div>
@using (Html.BeginForm(null, null, FormMethod.Post,new { @class = "dropzone", enctype = "multipart/form-data", id = "form" }))
{
@Html.AntiForgeryToken()
<div class="col-sm-12">
<div class="row">
<div class="col-sm-12">
<div class="form-group">
@Html.LabelFor(m => m.Categories)
@Html.DropDownListFor(m => m.Categories, (SelectList)Model.Categories, "", new { @class = "form-control col-sm-12" })
@Html.ValidationMessageFor(m => m.Categories)
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="dropzone-previews form-group">
</div>
</div>
</div>
<div class="row">
<div class="col-sm-12">
<hr />
</div>
</div>
<div class="row">
<div class="col-sm-12">
<div class="form-group">
<div class="clearfix">
<div class="pull-right">
<input type="submit" id="submit" value="Save" class="btn btn-primary" />
@Html.ActionLink("Cancel", "Index", @ViewContext.RouteData.Values["controller"].ToString(), new { }, new { @class = "btn btn-outline-secondary" })
</div>
</div>
</div>
</div>
</div>
</div>
}
<script>
Dropzone.options.form = {
autoProcessQueue: false,
uploadMultiple: true,
parallelUploads: 100,
init: function () {
var myDropzone = this;
// First change the button to actually tell Dropzone to process the queue.
this.element.querySelector("button[type=submit]").addEventListener("click", function (e) {
// Make sure that the form isn't actually being sent.
e.preventDefault();
e.stopPropagation();
myDropzone.processQueue();
});
// Listen to the sendingmultiple event. In this case, it's the sendingmultiple event instead
// of the sending event because uploadMultiple is set to true.
this.on("sendingmultiple", function () {
// Gets triggered when the form is actually being sent.
// Hide the success button or the complete form.
});
this.on("successmultiple", function (files, response) {
// Gets triggered when the files have successfully been sent.
// Redirect user or notify of success.
});
this.on("errormultiple", function (files, response) {
// Gets triggered when there was an error sending the files.
// Maybe show form again, and notify user of error
});
}
};
</script>
解决方案
在您的代码中尝试以下更改
添加 ' id="dropzonePreview" ' 在你想要的
<div class="col-sm-12">
<div class="dropzone-previews form-group" id="dropzonePreview">
</div>
</div>
在脚本中添加' previewpreviewsContainer: "#dropzonePreview", clickable: "#dropzonePreview" ',如下所示
Dropzone.options.form = {
autoProcessQueue: false,
uploadMultiple: true,
parallelUploads: 100,
previewpreviewsContainer: "#dropzonePreview",
clickable: "#dropzonePreview",...}
推荐阅读
- javascript - 从 CSS 字符串创建 CSSStyleSheet 对象?
- python - 在递归函数中使用python数组导致参考损失
- sql - 如何在一个查询中将 OUTPUT 的结果插入到同一张表中?
- r - 与 R 的混合模型中交互作用的影响大小
- multithreading - 多线程记录器在一段时间后崩溃,我找不到解决问题的方法
- scala - 没有创建 Tmp 文件中的数据
- vba - 将共享任务列表从 MS Outlook 导出到 Excel
- java - 如何在 Android 中使用 jsoniter codegen?
- ios - UIActivityViewController 未将动画 GIF 分享到 Twitter
- ios - 使用对象映射器映射响应