I'm struggeling with .NET 5 (MVC Framework). I would like to upload a file, but I don't know how to retrieve the uploaded file in the controller. The way it works on previous .NET Versions does not longer work (With HttpPostedFileBase, see an Example here).
My form is a very small form with a file input:
<form method="post" enctype="multipart/form-data">
<input type="file" name="file">
<input type="submit" name="submit" value="Upload">
</form>
My controller looks like this:
public class FittingController : Controller
{
[HttpPost]
public IActionResult Index(IndexViewModel viewModel)
{
// How to retrieve uploaded file here?
}
}
Has someone already made experiences with .NET Version 5?
Thanks in advance.
HttpPostedFileBaseis not aboutEntity Frameworkand you can use it to get posted file, then getbyte[]and file name from posted file and use them to save the file in database usingEF. Just as the link your question did it.