剃须刀页面上的Dropzone返回400状态代码 [英] Dropzone on razor Page returns 400 status code

查看:110
本文介绍了剃须刀页面上的Dropzone返回400状态代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ASP.NET core 2.0的RAZOR页面上使用DropZone以及其他类似这样的表单输入-

I am using DropZone on a RAZOR page in ASP.NET core 2.0 with other form inputs like this -

DzDemo.cshtml页面-

DzDemo.cshtml Page -

<form method="post" enctype="multipart/form-data">
    <input type="text" id="Username" name="Username" />
    <div class="dropzone" id="my-dropzone" name="mainFileUploader">
        <div class="fallback">
            <input name="file" type="file" multiple />
        </div>
    </div>
</form>
<div>
    <button type="submit" id="submit-all"> upload </button>
</div>

JS:-

Dropzone.options.myDropzone = {
            url: "/DzDemo?handler=Upload",
            autoProcessQueue: false,
            uploadMultiple: true,
            parallelUploads: 100,
            maxFiles: 100,
            acceptedFiles: "image/*",
           // paramName: myParamName,
            init: function () {

                var submitButton = document.querySelector("#submit-all");
                var wrapperThis = this;

                submitButton.addEventListener("click", function () {
                    wrapperThis.processQueue();
                });

                this.on('sendingmultiple', function (data, xhr, formData) {
                    formData.append("UserName", $("#Username").val());
                });
                this.on('error',
                    function (file, response) {
                        console.log(response);
                        alert(response);
                    });
            }
        };

DzDemo.cshtml.cs页面:-

DzDemo.cshtml.cs Page:-

[HttpPost]
        public IActionResult OnPostUpload()
        {
            var data = Request.Form; //This is 
            return Page();
        }

但是我从服务器得到400响应,并且我无法处理服务器端上载的文件.它也不会在服务器端加热Upload方法.请帮助

but I get 400 response from server and I am not able to process uploaded file server side Also it wont hot the Upload method on server side. Please help

推荐答案

如果在表单中缺少AntiforgeryToken,则将dropzone.js与Razor Pages一起使用将导致400的一件事.

One thing that will result in 400 using dropzone.js together with Razor Pages is if the AntiforgeryToken is missing from the form.

这通常是自动注入的,但是删除_viewimports或其taghelpers可以防止这种情况.

This is normally injected automatically but removing _viewimports or its taghelpers will prevent this.

要进行验证,只需在<form/>元素内添加此行,或在调试控制台中查看错误消息.

To verify just add this line inside the <form/> element or look at the debug console for error messages.

@Html.AntiForgeryToken()

这篇关于剃须刀页面上的Dropzone返回400状态代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆