title: @Html.EditorFor (Image)
body: <p>I am trying to allow a user to upload an image to our website and I'm not quite sure about how to use this. I have tried to use multiple types to define the image, including <code>System.Drawing.Image</code> and <code>HttpPostedFileWrapper</code> but the <code>@Html.EditorFor</code> always (understandably) brings up its attributes as fields to edit.</p>
  
  <p>In my view I did have, instead of <code>@Html.EditorFor</code> I did have <code>&lt;input type="file" name="imageToUpload" /&gt;</code> but it didn't get taken through to my view as part of the <code>Model</code>? I am quite new to MVC so I am hoping it is something trivial.</p>
  
  <p>Here is my View:</p>
  
  <pre><code>@using (Html.BeginForm()) {
      @Html.ValidationSummary(true)
      &lt;fieldset&gt;
          &lt;legend&gt;New Image&lt;/legend&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.Description)
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              @Html.EditorFor(model =&gt; model.Description)
              @Html.ValidationMessageFor(model =&gt; model.Description)
          &lt;/div&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.Image)
          &lt;/div&gt;
          &lt;div class="editor-field"&gt;
              &lt;input type="file" name="imageToUpload" /&gt;
          &lt;/div&gt;
  
          &lt;p&gt;
              &lt;input type="submit" value="Create" /&gt;
          &lt;/p&gt;
      &lt;/fieldset&gt;
  }
  </code></pre>
  
  <p>My Controller:</p>
  
  <pre><code>    [HttpPost]
      public ActionResult CreateImage(string brand, string collection, ImageEditViewModel imageEditViewModel)
      {
          string fileName = Guid.NewGuid().ToString();
          string serverPath = Server.MapPath("~");
          string imagesPath = serverPath + String.Format("Content\\{0}\\Images\\", Helper.Helper.ResolveBrand());
  
          string newLocation = Helper.Helper.SaveImage(fileName, imagesPath, imageEditViewModel.Image.InputStream)
  
          Image image = new Image
          {
              Collection = ds.Single&lt;Collection&gt;(c =&gt; c.Season == collection
                  &amp;&amp; c.Brand.Name == brand),
              Description = imageEditViewModel.Description,
              Location = "newLocation",
              Order = Helper.Helper.GetImageOrder(brand, collection)
          };
  
          ds.InsertOnSubmit&lt;Image&gt;(image);
          ds.SubmitChanges();
  
          return RedirectToAction("Brand");
      }
  </code></pre>
  
  <p>And finally the ViewModel:</p>
  
  <pre><code>public class ImageEditViewModel
  {
      public int CollectionId { get; set; }
  
      public string Description { get; set; }
  
      public HttpPostedFileWrapper Image { get; set; }
  
      public int Order { get; set; }
  }
  </code></pre>