0

我正在使用带有 dropzonejs 的 ASP.Net Core 2 Razorpages 在用户删除要重定向到我的 LoadingPage 的文件后在我的索引站点上进行拖放文件上传。

但是,我在重定向页面时遇到问题。奇怪的是,我要重定向到的页面的 OnGet() 方法正在被调用,但浏览器中的站点永远不会更新。其他重定向工作得很好,所以我怀疑问题出在 dropzonejs 上。

好吧,这是我的代码:

索引.cshtml

<div id="fileuploadcontainer">
            <form method="post"
                  class="dropzone"
                  id="music-dropzone"
                  asp-page="./Index">
            </form>
            <br />
</div>

index.cshtml.cs

public async Task<IActionResult> OnPostAsync(IFormFile file)
    {
        if (!ModelState.IsValid)
        {
            return Page();
        }

        [...]//this here is my file uploading, but the problem still persits even when removed

        return RedirectToPage("/LoadingPage/Loading");
    }

加载.cshtml.cs

public async Task<IActionResult> OnGet()
    {
        [...]//this part here gets called just fine, but the site doesnt redirect, even when it is minfied to only return Page() :(
        return Page();
    }

我也已经尝试删除异步修饰符,但无济于事......

编辑 - 解决方法: 我尝试了我能想到的任何可能的组合和解决方案,但我的问题仍然存在。但是我找到了一个很好的解决方法,您可以使用 dropzonejs 的事件,然后使用 JS 重定向页面。代码是:

<script>
    Dropzone.options.[yourDropzoneElementId] = {
        maxFilesize: 10, // Mb
        init: function () {
            // Set up any event handlers
            this.on('success', function () {

                window.location.replace("/LoadingPage/Loading");
            });
        }
    };
</script>

感谢您的帮助,谢谢!

4

0 回答 0