简体   繁体   English

Asp.net MVC + dropzoneJS文件上传

[英]Asp.net MVC + dropzoneJS file upload

I use DropzoneJS with MVC. 我使用DropzoneJS和MVC。 The file uploads fine, but action will not display another view, neither will display another view after redirected to another action. 文件上传很好,但操作不会显示另一个视图,也不会在重定向到另一个操作后显示另一个视图。 Just stays on the same view it was called from. 只是停留在它所调用的相同视图上。

Action : 行动:

    [HttpPost]
    public ActionResult FileUpload(HttpPostedFileBase file)
    {
        if(file != null)
        {
            string ext = Path.GetExtension(file.FileName);

            if (file.ContentLength > 0 && ext == ".txt")
            {
                var fileName = Path.GetFileName(file.FileName);

                if (fileName != null)
                {
                    var path = Path.Combine(Server.MapPath("~/uploads"), fileName);
                    file.SaveAs(path);
                }
            }
        }

        return View("Report");   

        // This will redirect to action but will not display another view either:
        // return RedirectToAction("Report"); 
     }

View called from: 查看来自:

<div id="dropzone">
    <form action="/Dashboard/FileUpload" class="dropzone clickable" id="demo-upload" method="post" enctype="multipart/form-data">
    </form>
</div>

you need to tell your browser to do the redirect, if you use dropzone to upload files asyncronsly. 如果使用dropzone上传文件asyncronsly,则需要告诉浏览器进行重定向。 With a async call to your MVC controller, MVC can't tell the browser to change page. 通过对MVC控制器的异步调用,MVC无法告诉浏览器更改页面。 You can do a redirect in javascript after dropzone have uploaded the files with the complete event: 在dropzone上传完整事件的文件后,您可以在javascript中进行重定向:

myDropzone.on("complete", function(file) {
  window.location = "./Dashboard/Report/";
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM