For a project i've been trying to upload a file from my view to my controller action. However, for some reason the action is reached but for the file i receive a null.
Here is my code:
Action:
[HttpPost]
[Route("UploadSickNote")]
public ActionResult UploadSickNote(HttpPostedFileBase file)
{
// Do something with file
return RedirectToAction("SickNotes");
}
View:
<form Controller="Documents" Action="UploadSickNote" method="post">
<div>
<input id="sicknote-upload" name="UploadedSickNote" asp-for="UploadedSickNote" type="file" accept="image/*" capture>
<input id="sicknote-button-submit" type="submit"/>
</div>
</form>
I have also tried using a viewmodel but with the same results.
Action:
[HttpPost]
[Route("UploadSickNote")]
public ActionResult UploadSickNote(SickNotesViewModel vm)
{
// Do something with file
return RedirectToAction("SickNotes");
}
ViewModel:
public class SickNotesViewModel
{
public List<SickNoteElement> SickNoteElements { get; set; }
public HttpPostedFileBase UploadedSickNote { get; set; }
}
I am using asp.net mvc 5 (not asp.net core) and a bit of vue.js for view functionalities. Any ideas or tips are greatly appreciated.