In Web Forms, when you drag a FileUpload control on to the designer, html form that wraps the entire page is decorated with an extra attribute: enctype="multipart/form-data" and method=”post”.

 

  • method=”post” - is needed because the form by default will be submitted via the HTTP get method.

  • enctype="multipart/form-data" - is needed to post form in multiple parts.

 

The FileUpload itself is rendered as an html input type=file. Within an MVC View, there are a number of ways to set this up. The first is with HTML:

 

<form action="/Home/UploadFile" method="post" enctype="multipart/form-data">
 <
input type="file" name="FileUpload" /><br />
 <
input type="submit" name="Submit" id="Submit" value="Upload" />
</
form>

 

 

In ASP.NET MVC this can be done using using the Html.BeginForm() extension method  as follows :

 

 

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

  
 <input type="file" name="FileUpload" /><br />
    <
input type="submit" name="Submit" id="Submit" value="Upload" />
}