Error When Uploading File: @using Html.BeginForm

May 7 2021 4:22 AM
I tried to upload a file using Html.BeginForm.
 
But I received an error saying:
 
HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly. Requested URL: /PCController/Progress
 
PCController is my controller's name. This is from my controller:
  1. [HttpGet]  
  2. public ActionResult Progress()  
  3. {  
  4. return View();  
  5. }  
  6. [HttpPost]  
  7. public ActionResult Progress(HttpPostedFile file)  
  8. {  
  9. try  
  10. {  
  11. if (file.ContentLength > 0)  
  12. {  
  13. string _FileName = Path.GetFileName(file.FileName);  
  14. string _path = Path.Combine(Server.MapPath("~/Content/PC"), _FileName);  
  15. file.SaveAs(_path);  
  16. }  
  17. ViewBag.Message = "File Uploaded Successfully!!";  
  18. return View();  
  19. }  
  20. catch  
  21. {  
  22. ViewBag.Message = "File upload failed!!";  
  23. return View();  
  24. }  
  25. }  
And this one is for my View:
  1. @using (Html.BeginForm("Progress""PCController", FormMethod.Post, new { enctype = "multipart/form-data" }))  
  2. {  
  3. <div>  
  4. @Html.TextBox("file"""new { type = "file" }) <br />  
  5. <input type="submit" value="Upload" />  
  6. @ViewBag.Message  
  7. </div>  
  8. }  

Answers (3)