title: Uploading file ASP MVC 4.0
body: <p>i'm trying to upload a file with ASP MVC4, i give you my situation:</p>
  
  <ul>
  <li>I have a model class "Movie" with some atributes (doesn't matter)</li>
  <li>I want to add some code to my controller and View part without touching the model, because we want to make the image difrent to the model.</li>
  </ul>
  
  <p>So, here's an example of my view code, i'll bold the lines added by me:</p>
  
  <pre><code>@using (Html.BeginForm()) {
  @Html.AntiForgeryToken()
  @Html.ValidationSummary(true)
  
  &lt;fieldset&gt;
      &lt;legend&gt;Movie&lt;/legend&gt;
          &lt;div class="editor-label"&gt;
          @Html.LabelFor(model =&gt; model.Duration)
      &lt;/div&gt;
      &lt;div class="editor-field"&gt;
          @Html.EditorFor(model =&gt; model.Duration)
          @Html.ValidationMessageFor(model =&gt; model.Duration)
      &lt;/div&gt;
  
  //ADDED BY ME:
      &lt;div class="editor-label"&gt;
          &lt;p&gt;Select a file&lt;/p&gt;
      &lt;/div&gt;
  
      &lt;div class="editor-field"&gt;
          &lt;input type="file" name="fileUpload" /&gt;
      &lt;/div&gt;//END OF MY CODE
  
      &lt;p&gt;
          &lt;input type="submit" value="Create" /&gt;
      &lt;/p&gt;
  &lt;/fieldset&gt;
  </code></pre>
  
  <p>So you can see that i have some code generated by ASP which allows me to add a new user to the db, and a "input" added by me to upload the image.</p>
  
  <p>The problem is that when i try to recover that image from the controller, the "Request.Files" atributte is empty, so i can't recover any image, and of course i can't upload it, here's my controller code:</p>
  
  <pre><code> [HttpPost]
      [ValidateAntiForgeryToken]
      public ActionResult Create(Movie movie)
      {
          if (ModelState.IsValid)
          {
              db.MovieContext.Add(movie);
              db.SaveChanges();
              foreach (string file in Request.Files)
              {
                  var postedFile = Request.Files[file];
                  postedFile.SaveAs(Server.MapPath("~/UploadedFiles") + pelicula.Id);
              }
              return RedirectToAction("Index");
          }
  
          return View(movie);
      }
  </code></pre>
  
  <p>Don't know why the "Request.Files" is empty, so if anyone can help me it would be great, Thank you so much</p>