title: upload image in folder MVC
body: <p>I am beginner in asp.net and trying to upload the image in my project Images folder but it is not uploading it in desired folder. Anybody please give me suggestion. </p>
  
  <p><strong>Create.cshtml</strong></p>
  
  <pre><code>@using (Html.BeginForm("Create", "Lenses", FormMethod.Post,
                              new { enctype = "multipart/form-data" }))
  {
      @Html.AntiForgeryToken()
  
      &lt;div class="form-horizontal"&gt;
          &lt;h4&gt;lens&lt;/h4&gt;
          &lt;hr /&gt;
          @Html.ValidationSummary(true, "", new { @class = "text-danger" })
  
  
          &lt;div class="form-group"&gt;
              @Html.LabelFor(model =&gt; model.lens_img, htmlAttributes: new { @class = "control-label col-md-2" })
              &lt;div class="col-md-10"&gt;
                  &lt;input type="file" name="file" id="file" style="width: 100%;" /&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="form-group"&gt;
          &lt;div class="col-md-offset-2 col-md-10"&gt;
              &lt;input type="submit" value="Create" class="btn btn-default" /&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;/div&gt;
  }
  </code></pre>
  
  <p><strong>Controller.cs</strong></p>
  
  <pre><code>[HttpPost]
  [ValidateAntiForgeryToken]
  public ActionResult Create([Bind(Include = "lens_img")] lens lens, HttpPostedFileBase file)
  {
      if (ModelState.IsValid)
      {
          if (file != null)
          {
              file.SaveAs(HttpContext.Server.MapPath("~/Content/Images/")
                                                            + file.FileName);
              lens.lens_img = file.FileName;
          }
          db.lenses.Add(lens);
          db.SaveChanges();
          return RedirectToAction("Index");
      }
  
      return View(lens);
  }
  </code></pre>