0

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.

2
  • 2
    HttpPostedFileBase is not about Entity Framework and you can use it to get posted file, then get byte[] and file name from posted file and use them to save the file in database using EF. Just as the link your question did it. Commented Dec 4, 2015 at 17:11
  • @RezaAghaei you are right, i think it has to do with .NET Version 5. I changed the question accordingly. Commented Dec 6, 2015 at 20:45

1 Answer 1

1

I found a solution myself. I access the file via the Request:

IFormFile file = Request.Form.Files.GetFile("file");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.