title: Image not posted to controller
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/8159725/mvc-httppostedfilebase-is-always-null">MVC. HttpPostedFileBase is always null</a>  </p>
  </blockquote>
  
  
  
  <p>I want users to be able to upload an image and store it on the server for later reference.</p>
  
  <p>Here's some code:</p>
  
  <p><strong>SliderController.cs:</strong></p>
  
  <pre><code>public ActionResult Create()
  {
    return View(new SliderImageViewModel());
  }
  
  [HttpPost]
  public ActionResult Create(SliderImageViewModel sliderImage)
  {
    if (ModelState.IsValid)
    {
      var slider = new SliderImage();
      var lastSortOrder =
        Context.SliderImages.Select(p =&gt; p.SortOrder).DefaultIfEmpty(0).Max();
      slider.SortOrder = lastSortOrder + 1;
  
      //TODO: upload image to server and get physical path (GUID)
      //slider.ImageUrl = physical path
  
      Context.SliderImages.Add(slider);
      Context.SaveChanges();
      return RedirectToIndex();
    }
    else
      return View(sliderImage);
  }
  
  
  public class SliderImageViewModel
  {
    [RequiredValue]
    public HttpPostedFileBase Image { get; set; }
    private string _Content;
    public string Content
    {
      get
      {
        if (string.IsNullOrWhiteSpace(_Content))
          return null;
        else
          return _Content;
      }
      set { _Content = value; }
    }
  }
  </code></pre>
  
  <p><strong>Create.cshtml:</strong></p>
  
  <pre><code>@using (Html.BeginForm("Create", "Slider", FormMethod.Post))
  {
    @Html.ValidationSummary(true)
  
    &lt;fieldset&gt;
      &lt;legend&gt;Page&lt;/legend&gt;
  
      &lt;div class="editor-label"&gt;
        @Html.Label("Content")
      &lt;/div&gt;
      &lt;div class="editor-field"&gt;
        @Html.TextBox("content")
      &lt;/div&gt;
  
      &lt;div class="editor-label"&gt;
        @Html.Label("Image")
      &lt;/div&gt;
      &lt;div class="editor-field"&gt;
        @Html.TextBox("image", null, new { type = "file", accept = "image/*" })
      &lt;/div&gt;
  
      &lt;p&gt;
        &lt;input type="submit" value="Save" /&gt;
      &lt;/p&gt;
  
    &lt;/fieldset&gt;
  }
  </code></pre>
  
  <p>When I submit the form, the <code>Image</code> property in the <code>sliderImage</code> argument is null (the <code>Content</code> works tho), how should I fix this?</p>