Request.Files.Count always 0 while uploading image in MVC 5

I wasted so much time and it turns out that all I needed to do was to use the name attribute as well

 <input type="file" name="somename"> 

the name attribute was missing in my new project.


To add on You need to change the post method.

Need to add:

new { enctype = "multipart/form-data" }

Here is complete form tag

@using (Html.BeginForm("Cars", "Expense", FormMethod.Post, 
      new { enctype = "multipart/form-data" }))

Those lines are essential; without them, you will not be able to save an input of type file. I sat for 6 hours trying to figure that out.


You need to change the post method

Need to add:

new { enctype = "multipart/form-data" }

Here is complete form tag

@using (Html.BeginForm("Cars", "Expense", FormMethod.Post, 
      new { enctype = "multipart/form-data" }))

See how can you post multiple files