ASP.NET MVC Uploading and Downloading Files

Uploading files is pretty straight forward with ASP.NET MVC 5, but there are few things to be aware of to make things go a bit smoother.


Razor View

The view needs to have the enctype set as shown below. Also, if you are using the TextFor HtmlHelper, make sure you set the File type of the control.

Model and Controller Actions

A simple model uses the HttpPostedFileBase to access the file. Below there are two controller actions which provide the mechanism to upload and download the customer statment:


The file download makes use of the Controller.File method to return a FileContentResult. You can find out more information about the different ActionResult classes on msdn at Controllers and Action Methods in ASP.NET MVC Applications

Popular posts from this blog

A Simple 3 Layer Architecture