I am about to hit my head against the keyboard - as per video attached my photo upload onto my ASP.NET app always fails. The culprit seems to be the files in this code
[System.Web.Mvc.HttpPost] public async Task<JsonResult> UploadListingImage() { String result = string.Empty; var files = Request.Form.Files; //Debug shows files is always null foreach (IFormFile sourceFile in files) //files is null so it does not go thru the loop { string FileName = sourceFile.Name + ".jpg"; string imagepath = GetActualPath(FileName); try { if (System.IO.File.Exists(imagepath)) { System.IO.File.Delete(imagepath); } using (FileStream stream = System.IO.File.Create(imagepath)) { await sourceFile.CopyToAsync(stream); result = "pass"; } } catch (ArgumentNullException exp) { Console.WriteLine("Please provide a valid file path."); } } return Json(result); //once the loop is skipped the operation directly returns this one }
[System.Web.Mvc.HttpPost] public async Task<JsonResult> UploadListingImage() { String result = string.Empty; var files = Request.Form.Files; //Debug shows files is always null foreach (IFormFile sourceFile in files) //files is null so it does not go thru the loop { string FileName = sourceFile.Name + ".jpg"; string imagepath = GetActualPath(FileName); try { if (System.IO.File.Exists(imagepath)) { System.IO.File.Delete(imagepath); } using (FileStream stream = System.IO.File.Create(imagepath)) { await sourceFile.CopyToAsync(stream); result = "pass"; } } catch (ArgumentNullException exp) { Console.WriteLine("Please provide a valid file path."); } } return Json(result); //once the loop is skipped the operation directly returns this one }
` Could anyone kindly point me in the right direction as to why files always go null in this code? For the full contect here is my code https://paste.mod.gg/azthzgzpckja/0