【发布时间】:2020-03-10 03:35:13
【问题描述】:
我在我的剃刀视图中有这个:
<div id="dropzone">
<form action="/Controller/Upload" method="post" enctype="multipart/form-data"
id="my-awesome-dropzone" class="dropzone needsclick dz-clickable dropzone-previews">
@Html.AntiForgeryToken()
<div ></div>
<div class="dz-message needsclick">
<button type="button" class="dz-button">Drop files here or click to upload.</button><br />
</div>
<span class="note needsclick">
</span>
</form>
这在我的 js 中:
Dropzone.options.myAwesomeDropzone = {
paramName: "file", // The name that will be used to transfer the file
maxFiles: mediaMax,
maxFilesize: maxSize,
uploadMultiple: true,
accept: function (file, done) {
if (file.name === "justinbieber.jpg") {
done("Naha, you don't.");
}
else { done(); }
},
init: function () {
this.on("sending", function (file, response, formData) {
formData["__RequestAntiForgeryToken"] = document.getElementsByName("__RequestVerificationToken")[1].value;
});
this.on("sendingmultiple", function (file, response, formData) {
formData["__RequestAntiForgeryToken"] = document.getElementsByName("__RequestVerificationToken")[1].value;
});
this.on("success", function (file, response) {
file.serverID = response.id;
});
this.on("error", function (file, response) {
var r = response;
console.log("Drop Err:");
console.log(r);
});
}};
在我的控制器中我试过这个:
[HttpPost]
[FormAttributes.DisableFormValueModelBinding]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Upload(ICollection<IFormFile> files)
还有这个
[HttpPost]
[FormAttributes.DisableFormValueModelBinding]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Upload(IFormFile file)
文件和文件都返回 0 或 null
唯一有效的是
[HttpPost]
[FormAttributes.DisableFormValueModelBinding]
[ValidateAntiForgeryToken]
public async Task<IActionResult> Upload(ICollection<IFormFile> files)
{
if (ModelState.IsValid)
{
var more = HttpContext.Request.Form.Files;
... do stuff
} }
我基本上忽略了文件的输入参数
谁能告诉我上传的正确参数是什么?
对于参考,我查看了以下链接:
MVC 6 HttpPostedFileBase?
https://dotnetthoughts.net/uploading-images-aspnet-core-and-dropzone/
【问题讨论】:
标签: asp.net-mvc asp.net-core dropzone.js