简体   繁体   中英

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. The PDF file is processed and the information is stored in a db. After the controller processes the PDF I need it to redirect to a confirmation View. 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

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

        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

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

Use this code

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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