title: In MVC4, how do I upload a file (an image) to SQL Server that's part of my domain model?
body: <p>I'm relatively new to MVC, and I've never had to deal with uploading a file (an image, specifically) to a SQL Server database. To be honest, I don't know what I'm doing here.  </p>
  
  <p>Here's what I have so far - here's my domain model (note the <code>HttpPostedFileBase</code> in my model - this is what I want to upload):</p>
  
  <pre><code>public class Profile
  {
      [Key]
      public int Id { get; set; }
  
      [Required(ErrorMessage="Years of service is required")]
      [DisplayName("Years Service:")]
      public int YearsService { get; set; }
  
      [DataType(DataType.MultilineText)]
      [DisplayName("Notable Achivements:")]
      public string NotableAchivements { get; set; }
  
      [Required(ErrorMessage = "Technical skills are required")]
      [DataType(DataType.MultilineText)]
      [DisplayName("Technical Skills:")]
      public string TechnicalSkills { get; set; }
  
      [DisplayName("Upload Image: ")]
      public HttpPostedFileBase Photo { get; set; }
  
      public string CreatedBy { get; set; }
      public DateTime CreatedDate { get; set; }
      public string ModifiedBy { get; set; }
      public DateTime ModifiedDate { get; set; }
  }
  </code></pre>
  
  <p>And here's my view:</p>
  
  <pre><code>@using (Html.BeginForm("Create", "Profiles", FormMethod.Post, new { enctype = "multipart/form-data" }))
  {
  &lt;div class="editor-label"&gt;
      @Html.LabelFor(model =&gt; model.YearsService)
  &lt;/div&gt;
  &lt;div class="editor-field"&gt;
      @Html.EditorFor(model =&gt; model.YearsService)
      @Html.ValidationMessageFor(model =&gt; model.YearsService)
  &lt;/div&gt;
  
  &lt;div class="editor-label"&gt;
      @Html.LabelFor(model =&gt; model.NotableAchivements)
  &lt;/div&gt;
  &lt;div class="editor-field"&gt;
      @Html.EditorFor(model =&gt; model.NotableAchivements)
      @Html.ValidationMessageFor(model =&gt; model.NotableAchivements)
  &lt;/div&gt;
  
  &lt;div class="editor-label"&gt;
      @Html.LabelFor(model =&gt; model.TechnicalSkills)
  &lt;/div&gt;
  &lt;div class="editor-field"&gt;
      @Html.EditorFor(model =&gt; model.TechnicalSkills)
      @Html.ValidationMessageFor(model =&gt; model.TechnicalSkills)
  &lt;/div&gt;
  
  &lt;input type="file" name="photo" /&gt;
  &lt;input type="submit" name="Submit" id="Submit" value="Upload" /&gt;
  }
  </code></pre>
  
  <p>I hope there's something glaringly obvious that I'm doing wrong.  Can anyone provide advice on how to do a simple file upload to a SQL Server database?</p>