FeaturedIT topics

How to upload files in ASP.Net Core MVC

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 download it here

Next, follow the steps given below to create a new ASP.Net Core project in Visual Studio.

  1. Launch the Visual Studio IDE.
  2. Click on “Create new project.”
  3. In the “Create new project” window, select “ASP.Net Core Web Application” from the list of the templates displayed.
  4. Click Next. 
  5. In the “Configure your new project” window, specify the name and location for the new project.
  6. Click Create. 
  7. A new window, “Create New ASP.Net Core Web Application,” is shown next.
  8. Select .Net Core as the runtime and ASP.Net Core 2.2 (or later) from the drop-down list at the top.
  9. Select “Web Application (Model-View-Controller)” as the project template.
  10. Ensure that the check boxes “Enable Docker Support” and “Configure for HTTPS” are unchecked as we won’t be using those features here.
  11. Ensure that Authentication is set as “No Authentication” as we won’t be using authentication either.
  12. Click Create.

Related Articles

Back to top button