title: System.Web.HttpPostedFileWrapper Error when upload Images to Database in MVC C#
body: <p>I have a problem here.  When I remove <code>(&quot;Create&quot;, &quot;DriverRegs&quot;, FormMethod.Post, new { enctype = &quot;multipart/form-data&quot; })</code> from my BeginForm, the image path is stored on database normally, but when I put it the above back to the BeginForm, then the image file is stored on my folder but on database appears this error <code>System.Web.HttpPostedFileWrapper</code>.  What is wrong with the codes?
  I would appreciate it if someone could help me.
  Thanks in advance.</p>
  <p>here are my codes:</p>
  <p><strong>CONTROLLER</strong></p>
  <pre><code>public ActionResult Create(DriverReg model, HttpPostedFileBase file)       
  {
          if (ModelState.IsValid)
          {
              if (file != null &amp;&amp; file.ContentLength &gt; 0)
              {
                  var fileName = Path.GetFileName(file.FileName);
                  var phisicalPath = Path.Combine(Server.MapPath(&quot;~/Content/uploads/&quot;), fileName);
                  file.SaveAs(phisicalPath);
                  DriverReg newRecord = new DriverReg();
                  newRecord.FullName = model.FullName;
                  newRecord.Address = model.Address;
                  newRecord.Postcode = model.Postcode;
                  newRecord.Contact = model.Contact;
                  newRecord.Email = model.Email;
                  newRecord.County = model.County;
                  newRecord.File = phisicalPath;
              }
              db.DriverRegs.Add(model);
              db.SaveChanges();
              return RedirectToAction(&quot;Index&quot;);
          }
  
          return View(model);
      }
  </code></pre>
  <p><strong>MODEL</strong></p>
  <pre><code> public class DriverReg
      {
          [Key]
          public int DrvId { get; set; }
          public string FullName { get; set; }
          public string Address { get; set; }
          public string Postcode { get; set; }
          public string Contact { get; set; }
          public string Email { get; set; }
          public string County { get; set; }
          [DataType(DataType.Upload)]
          [Display(Name = &quot;Upload Files&quot;)]
          [Required(ErrorMessage = &quot;Please choose file to upload&quot;)]
          public string File { get; set; }
          public DateTime Date { get; set; }
  
  
          internal int UploadImageInDataBase(HttpPostedFileBase file, DriverRegViewModel model)
          {
              throw new NotImplementedException();
          }
  
      }
      public class DriverDbContext : DbContext
      {
          public DriverDbContext()
              : base(&quot;VanRemovals&quot;)
          {
          }
  
      public static DriverDbContext Create()
          {
              return new DriverDbContext();
          } 
  
            public DbSet&lt;DriverReg&gt; DriverRegs { get; set; }
      }
  </code></pre>
  <p><strong>VIEW</strong></p>
  <pre><code> @using (Html.BeginForm(&quot;Create&quot;, &quot;DriverRegs&quot;, FormMethod.Post, new { enctype = &quot;multipart/form-data&quot; }))
      {
          @Html.AntiForgeryToken()
          
          &lt;div class=&quot;form-horizontal&quot;&gt;
              &lt;h4&gt;DriverReg&lt;/h4&gt;
              &lt;hr /&gt;
              @Html.ValidationSummary(true, &quot;&quot;, new { @class = &quot;text-danger&quot; })
              &lt;div class=&quot;form-group&quot;&gt;
                  @Html.LabelFor(model =&gt; model.FullName, htmlAttributes: new { @class = &quot;control-label col-md-2&quot; })
                  &lt;div class=&quot;col-md-10&quot;&gt;
                      @Html.EditorFor(model =&gt; model.FullName, new { htmlAttributes = new { @class = &quot;form-control&quot; } })
                      @Html.ValidationMessageFor(model =&gt; model.FullName, &quot;&quot;, new { @class = &quot;text-danger&quot; })
                  &lt;/div&gt;
              &lt;/div&gt;
      
              &lt;div class=&quot;form-group&quot;&gt;
                  @Html.LabelFor(model =&gt; model.Address, htmlAttributes: new { @class = &quot;control-label col-md-2&quot; })
                  &lt;div class=&quot;col-md-10&quot;&gt;
                      @Html.EditorFor(model =&gt; model.Address, new { htmlAttributes = new { @class = &quot;form-control&quot; } })
                      @Html.ValidationMessageFor(model =&gt; model.Address, &quot;&quot;, new { @class = &quot;text-danger&quot; })
                  &lt;/div&gt;
              &lt;/div&gt;
      
              &lt;div class=&quot;form-group&quot;&gt;
                  @Html.LabelFor(model =&gt; model.Postcode, htmlAttributes: new { @class = &quot;control-label col-md-2&quot; })
                  &lt;div class=&quot;col-md-10&quot;&gt;
                      @Html.EditorFor(model =&gt; model.Postcode, new { htmlAttributes = new { @class = &quot;form-control&quot; } })
                      @Html.ValidationMessageFor(model =&gt; model.Postcode, &quot;&quot;, new { @class = &quot;text-danger&quot; })
                  &lt;/div&gt;
              &lt;/div&gt;
      
              &lt;div class=&quot;form-group&quot;&gt;
                  @Html.LabelFor(model =&gt; model.Contact, htmlAttributes: new { @class = &quot;control-label col-md-2&quot; })
                  &lt;div class=&quot;col-md-10&quot;&gt;
                      @Html.EditorFor(model =&gt; model.Contact, new { htmlAttributes = new { @class = &quot;form-control&quot; } })
                      @Html.ValidationMessageFor(model =&gt; model.Contact, &quot;&quot;, new { @class = &quot;text-danger&quot; })
                  &lt;/div&gt;
              &lt;/div&gt;
      
              &lt;div class=&quot;form-group&quot;&gt;
                  @Html.LabelFor(model =&gt; model.Email, htmlAttributes: new { @class = &quot;control-label col-md-2&quot; })
                  &lt;div class=&quot;col-md-10&quot;&gt;
                      @Html.EditorFor(model =&gt; model.Email, new { htmlAttributes = new { @class = &quot;form-control&quot; } })
                      @Html.ValidationMessageFor(model =&gt; model.Email, &quot;&quot;, new { @class = &quot;text-danger&quot; })
                  &lt;/div&gt;
              &lt;/div&gt;
      
              &lt;div class=&quot;form-group&quot;&gt;
                  @Html.LabelFor(model =&gt; model.County, htmlAttributes: new { @class = &quot;control-label col-md-2&quot; })
                  &lt;div class=&quot;col-md-10&quot;&gt;
                      @Html.EditorFor(model =&gt; model.County, new { htmlAttributes = new { @class = &quot;form-control&quot; } })
                      @Html.ValidationMessageFor(model =&gt; model.County, &quot;&quot;, new { @class = &quot;text-danger&quot; })
                  &lt;/div&gt;
              &lt;/div&gt;
      
              &lt;div class=&quot;form-group&quot;&gt;
                  @Html.LabelFor(model =&gt; model.File, htmlAttributes: new { @class = &quot;control-label col-md-2&quot; })
                  &lt;div class=&quot;col-md-10&quot;&gt;
                      &lt;input type=&quot;file&quot; class=&quot;file-input&quot; name=&quot;file&quot; /&gt;
                      @Html.ValidationMessageFor(model =&gt; model.File, &quot;&quot;, new { @class = &quot;text-danger&quot; })
                  &lt;/div&gt;
              &lt;/div&gt;
      
              &lt;div class=&quot;form-group&quot;&gt;
                  @Html.LabelFor(model =&gt; model.Date, htmlAttributes: new { @class = &quot;control-label col-md-2&quot; })
                  &lt;div class=&quot;col-md-10&quot;&gt;
                      @Html.EditorFor(model =&gt; model.Date, new { htmlAttributes = new { @class = &quot;form-control&quot; } })
                      @Html.ValidationMessageFor(model =&gt; model.Date, &quot;&quot;, new { @class = &quot;text-danger&quot; })
                  &lt;/div&gt;
              &lt;/div&gt;
      
              &lt;div class=&quot;form-group&quot;&gt;
                  &lt;div class=&quot;col-md-offset-2 col-md-10&quot;&gt;
                      &lt;input type=&quot;submit&quot; value=&quot;Create&quot; class=&quot;btn btn-default&quot; /&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      }
      
      &lt;div&gt;
          @Html.ActionLink(&quot;Back to List&quot;, &quot;Index&quot;)
      &lt;/div&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>