title: upload image in server folder and save path in Sqlserver using entity framework mvc4
body: <p>I am trying to save picture in folder and store path in Sqlserver 2008 using entity framework. I need register the user with picture. My code is saving all the data in database except picture and picture path.</p>
  
  <pre><code>My model is 
  
   {
      using System;
      using System.Collections.Generic;
      using System.ComponentModel.DataAnnotations;
      public partial class customer
      {
  
          [Display(Name="Username")]
          public string user_id { get; set; }
  
          [Display(Name = "Password")]
          public string password { get; set; }
  
          [Display(Name = "First Name")]
          public string first_name { get; set; }
  
          [Display(Name = "Last Name")]
          public string last_name { get; set; }
  
          [Display(Name = "Address")]
          public string address { get; set; }
  
          [Display(Name = "City")]
          public string city { get; set; }
  
          [Display(Name = "State")]
          public string state { get; set; }
  
          [Display(Name = "Zip")]
          public Nullable&lt;int&gt; zip { get; set; }
  
          [Display(Name = "Country")]
          public string country { get; set; }
  
          [Display(Name = "Email Address")]
          public string email { get; set; }
  
          [Display(Name = "Phone")]
          public string phone { get; set; }
  
          [Display(Name = "Picture")]
          public string picture { get; set; }
  
          [Display(Name = "Registration Date")]
          public Nullable&lt;System.DateTime&gt; reg_date { get; set; }
  
          [Display(Name = "Status")]
          public string status { get; set; }
  
          [Display(Name = "Keep me logged in")]
          public bool rememberme { get; set; }
       }
   }
  
  My Controller is 
  
  [HttpPost]
          public ActionResult Register(customer customer, HttpPostedFileBase file)
          {
              if (ModelState.IsValid)
              {
                  if (file != null)
                  {
                          file.SaveAs(HttpContext.Server.MapPath("~/image/") + file.FileName);
                          customer.picture = file.FileName;
                  }
                  onlinebookstoreEntities1 db = new onlinebookstoreEntities1();
                  db.customers.Add(customer);
                  db.SaveChanges();
                  return RedirectToAction("Index","Home");
              }
  
              return View(customer);
          }
  
  
  and my view is 
  
  
  @using (Html.BeginForm("Register", "Account", FormMethod.Post, new { enctype = "multipart/form-data" })) {
  
  
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.first_name)
          &lt;/div&gt;
          &lt;div class="txtreg"&gt;
              @Html.EditorFor(model =&gt; model.first_name)
          &lt;/div&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.last_name)
          &lt;/div&gt;
          &lt;div class="txtreg"&gt;
              @Html.EditorFor(model =&gt; model.last_name)
          &lt;/div&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.user_id)
          &lt;/div&gt;
          &lt;div class="txtreg"&gt;
              @Html.EditorFor(model =&gt; model.user_id)
          &lt;/div&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.password)
          &lt;/div&gt;
          &lt;div class="txtreg"&gt;
              @Html.EditorFor(model =&gt; model.password)
          &lt;/div&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.address)
          &lt;/div&gt;
          &lt;div class="txtreg"&gt;
              @Html.EditorFor(model =&gt; model.address)
          &lt;/div&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.city)
          &lt;/div&gt;
          &lt;div class="txtreg"&gt;
              @Html.EditorFor(model =&gt; model.city)
          &lt;/div&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.state)
          &lt;/div&gt;
          &lt;div class="txtreg"&gt;
              @Html.EditorFor(model =&gt; model.state)
          &lt;/div&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.zip)
          &lt;/div&gt;
          &lt;div class="txtreg"&gt;
              @Html.EditorFor(model =&gt; model.zip)
          &lt;/div&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.country)
          &lt;/div&gt;
          &lt;div class="txtreg"&gt;
              @Html.EditorFor(model =&gt; model.country)
          &lt;/div&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.email)
          &lt;/div&gt;
          &lt;div class="txtreg"&gt;
              @Html.EditorFor(model =&gt; model.email)
          &lt;/div&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.phone)
          &lt;/div&gt;
          &lt;div class="txtreg"&gt;
              @Html.EditorFor(model =&gt; model.phone)
          &lt;/div&gt;
  
          &lt;div class="editor-label"&gt;
              @Html.LabelFor(model =&gt; model.picture)
          &lt;/div&gt;
          &lt;div class="btnreg"&gt;
             &lt;input type="file" id="picture" value="Upload Picture" /&gt;
          &lt;/div&gt;
  
  
          &lt;div class="txtreg"&gt;
              @Html.CheckBoxFor(model =&gt; model.rememberme)   @Html.LabelFor(model =&gt; model.rememberme)
          &lt;/div&gt;
  
              &lt;input type="submit" value="Create Account" name="btnsub" /&gt;
  
  }
  </code></pre>