无法让Dropzone.js发送其他数据

我使用的是带有.net核心3.1的Dropzone.js。我可以让它调用我的控制器操作,但我不能让它随请求发送任何额外的数据。

这是我的表格:

<form action="/api/photos/"
          class="dropzone needsclick dz-clickable"
          id="image-upload"
          method="post">
        <input type="hidden" name="eventId" value="1"/>
        <div class="dz-message needsclick">
            <span class="note needsclick">
                Drop files here or click to upload.
            </span>
        </div>
    </form>

这是我的Javascript:

<script>
            Dropzone.options.imageUpload = {
                dictDefaultMessage: "Drop files here or Click to Upload",
                addRemoveLinks: true, // Allows for cancellation of file upload and remove thumbnail
                init: function () {
                myDropzone = this;
                    myDropzone.on("sending", function (file, xhr, data) {
                data.append("message", "hello world");
                        console.log(data);
                    });
                    myDropzone.on("success", function (file, response) {
                console.log("Success");
                        myDropzone.removeFile(file);
                    });
                }
            };
    </script>

这是我的控制器端点

public async Task<IActionResult> PostPhoto(List<IFormFile> file)
        {
            ..code removed..
        }

正如您所看到的,我在表单中有一个隐藏字段,它应该已经将数据与请求一起发送,并且我还尝试通过JS向表单数据追加一个值,但要么没有发送,要么我找不到它。我查看了dev工具的网络面板,只能看到正在发送的图像,其他什么也看不到。或者,如果它正在发送,我如何在控制器中找到它?我已经在这上面花了很长时间了,这有点烦人,请帮帮忙!

转载请注明出处:http://www.txqp3.com/article/20230526/2588465.html