简体   繁体   English

异步任务控制器未重定向到操作

[英]async task controller not redirecting to action

I have an async task action controller called Upload, which allows a user to upload a PDF file.我有一个名为 Upload 的异步任务操作控制器,它允许用户上传 PDF 文件。 The PDF file is processed and the information is stored in a db.处理 PDF 文件并将信息存储在 db 中。 After the controller processes the PDF I need it to redirect to a confirmation View.控制器处理完 PDF 后,我需要将其重定向到确认视图。 Currently after the Upload controller finishes, I get no server eg 404 error etc, it simply redirects to the same Upload View, instead of Confirmation View目前上传控制器完成后,我没有得到服务器,例如 404 错误等,它只是重定向到同一个上传视图,而不是确认视图

Can anyone tell me why?谁能告诉我为什么? I'm pretty sure it has something to do with async tasks, maybe async tasks need to be redirected in a different way?我很确定它与异步任务有关,也许异步任务需要以不同的方式重定向?

My Upload & Confirmation Actions in CompletedCamps Controller我在 CompletedCamps Controller 中的上传和确认操作

        public ActionResult Upload(int? id)
        {
            CompletedCamp completedCamp = db.CompletedCamps.Find(id);
            return View(completedCamp);
        }

        [HttpPost]
        public async Task<ActionResult> Upload(HttpPostedFileBase file, int? id)
        {
            CompletedCamp completedCamp = db.CompletedCamps.Find(id);

            string filename = Guid.NewGuid() + Path.GetExtension(file.FileName);
            string filepath = Server.MapPath(Path.Combine("~/Surveys/", filename));
            file.SaveAs(filepath);

            completedCamp.SurveyName = filename;
            db.SaveChanges();

            await AzureVisionAPI.ExtractToTextFile(filepath);
            ParseSurveyText parse1 = new ParseSurveyText();
            await Task.Run(() => parse1.ParseTextFile(completedCamp.RollNumber, completedCamp.OfficialSchoolName, completedCamp.Date, filepath));

            return RedirectToAction("Confirmation", "CompletedCamps", new { id = id });
        }

        [HttpGet]
        public ActionResult Confirmation(int? id)
        {
            var camp = db.CompletedCamps.FirstOrDefault(c => c.Id == id);
            return View(camp);
        }

If you want redirect to Confirmation Controller and Confirmation Action ,please test this code, instead of如果您想重定向到Confirmation ControllerConfirmation Action ,请测试此代码,而不是

return RedirectToAction("Confirmation", "CompletedCamps", new { id = id });

Use this code使用此代码

return RedirectToAction("Confirmation", "Confirmation", new { id = id });

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

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