ASP.Net Core MVC provides support for uploading files through model binding that leverages the IFormFile interface. Recall that model binding maps data from an HTTP request to action method parameters. Model binding simplifies access to the data sent by an HTTP request and makes it easier for the action methods to be unit tested. The IFormFile interface simply represents a file sent with an HTTP request.
We can take advantage of the IFormFile interface in our ASP.Net Core MVC applications to represent a file that is sent from the client to the server along with the HTTP request. This article presents a discussion of how we can upload files in ASP.Net Core MVC.
Create an ASP.Net Core MVC project
First off, let’s create an ASP.Net Core MVC project in Visual Studio. At the time of this writing, Visual Studio 2019 is available for free download. If you don’t have a copy of Visual Studio 2019 installed in your system, you can .
Next, follow the steps given below to create a new ASP.Net Core project in Visual Studio.
- Launch the Visual Studio IDE.
- Click on “Create new project.”
- In the “Create new project” window, select “ASP.Net Core Web Application” from the list of the templates displayed.
- Click Next.
- In the “Configure your new project” window, specify the name and location for the new project.
- Click Create.
- A new window, “Create New ASP.Net Core Web Application,” is shown next.
- Select .Net Core as the runtime and ASP.Net Core 2.2 (or later) from the drop-down list at the top.
- Select “Web Application (Model-View-Controller)” as the project template.
- Ensure that the check boxes “Enable Docker Support” and “Configure for HTTPS” are unchecked as we won’t be using those features here.
- Ensure that Authentication is set as “No Authentication” as we won’t be using authentication either.
- Click Create.