title: Upload Image ASP.NET MVC
body: <p>Hey I want to upload picture and save that picture to a folder, and save the name of that picture to DB in addition I am also using model binding for other fields of form. Here is the code in this HttpPostedFileBase file receives null I am also using enctype = "multipart/form-data" in my form.</p>
  
  <pre><code>public ActionResult UmrahPackage(PackagesModel model, , HttpPostedFileBase file)
      {
          try
          {
              if (model.ID == 0)
              {
                  String fileName = "";
                  Pakage pkg = new Pakage();
                  pkg.Title = model.Title;
                  pkg.PackageDetail = model.PackageDetail;
                  pkg.Duration = model.Duration;
  
                  if (file != null)
                  {
                      fileName = System.Guid.NewGuid().ToString() + System.IO.Path.GetExtension(file.FileName);
                      string physicalPath = Server.MapPath("~/Images/Uploads" + fileName);
                      // save image in folder
                      file.SaveAs(physicalPath);
                  }}
  </code></pre>
  
  <p>In addition I am also trying this but I am not be able to understand that how to save image in folder I mean the object instance before SaveAs -> file</p>
  
  <pre><code>if (Request.Files.Count &gt; 0 &amp;&amp; String.IsNullOrEmpty(Request.Files[0].FileName) == false)
                  {
                      HttpPostedFileBase file;
                      fileName = System.Guid.NewGuid().ToString() + System.IO.Path.GetExtension(Request.Files[0].FileName);
                      string physicalPath = Server.MapPath("/uploads/profileimages/") + fileName;
                      file.SaveAs(physicalPath);
                  }
  </code></pre>
  
  <p>My form looks like,</p>
  
  <pre><code>    @using (Html.BeginForm("UmrahPackage", "Home", FormMethod.Post, new { enctype = "multipart/form-data"}))
                  {
                      @Html.HiddenFor(model =&gt; model.ID)
  
                      &lt;label&gt;Title:&lt;/label&gt;
                      @Html.TextBoxFor(model =&gt; model.Title)
  
                      &lt;label&gt;Upload Image&lt;/label&gt;
                      &lt;input type="file" id="imgInp"&gt;
  
                      &lt;button type="submit" &gt;Create&lt;/button&gt;
                  }
  </code></pre>
  
  <p>Kindly help me, Thanks.</p>