Multiple file upload in mvc 5 with razor example

Multiple file upload in mvc 5 with razor example

In this tutorial i am going to explain about multiple file upload in mvc 5 with razor example. In my previous tutorial i have explained about

Implementation :

Now we will see the implementation of multiple file upload in mvc 5 with razor example.

  1. Open visual studio and create new web application. Select mvc as your template.
  2. Once the project is loaded right click on controllers folder and add new controller called uploadcontroller.
  3. Add two action methods named UploadFile. One for get and another one for post.
  4. Now add the view and add a file upload control with multiple attribute abd button.
  5. Please not file upload input control should have name property else you always get null in controller action.
  6. And also name of the file upload input should be same as action method parameter. That is in our case it is userFile.



Below is my complete controller code.

C#.Net:

VB.Net:

In the above uploadFile – post action method, first i am checking whether the directory exists. If not i am creating directory. And then using foreach loop i am looping through HttpPostedFileBase list and uploading it to the directory.

Output:

Now if you run the program you can see the output of multiple file upload in mvc 5 with razor example. Click on choose files. It will open the file chooser dialog. Navigate the required folder and choose images to upload. It will upload the images and show the success message with uploaded files count.

Output of Multiple file upload in mvc 5 with razor example

Conclusion:

Hope you learned multiple file upload in mvc 5 with razor example. Do you like this tutorial? Help us to improve. Please post your comments and feedback below.

Search Terms:

how to upload multiple files in mvc 4,mvc multiple file upload httppostedfilebase,multiple file upload in mvc 4 using jquery,upload multiple files in asp.net mvc using jquery,httppostedfilebase multiple files,multiple file upload in mvc using jquery,mvc 5 file upload to database,mvc 5 file upload example

Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!