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 e.g. 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);
}