title: Want to save a image to a folder and saving the url in database
body: <p>I very newbie in asp.net mvc . here I had a problem in the controller image upload anyone can give help ?? This example controller I get from the internet , what should I change and code viewnya like, here I want to save the image through " AvatarUrl "</p>
  
  <h1>Model > EmployeeServices</h1>
  
  <pre><code>public class EmployeeModel{
  
      [ScaffoldColumn(false)]
      public int EmployeeID { get; set; }
  
      [Required(ErrorMessage = "Please Enter Position ID")]
      public int PositionID { get; set; }
  
      [Required(ErrorMessage = "Please Enter NO PEK")]
      public string NoPEK { get; set; }
  
      [Required(ErrorMessage = "Please Enter NO KTP")]
      public string NoKTP { get; set; }
  
      [Required(ErrorMessage = "Please Enter TaxID")]
      public string TaxID { get; set; }
  
      [Required(ErrorMessage = "Please Enter FirstName")]
      public string FirstName { get; set; }
  
      [Required(ErrorMessage = "Please Enter LastName")]
      public string LastName { get; set; }
  
      [Required(ErrorMessage = "Please Enter OrganizationID")]
      public int OrganizationID { get; set; }
  
      [Required(ErrorMessage = "Please Enter BirthPlace")]
      public string BirthPlace { get; set; }
  
      [Required(ErrorMessage = "Please Enter BirthDay")]
      public System.DateTime BirthDay { get; set; }
  
      [Required(ErrorMessage = "Please Enter Gender")]
      public string Gender { get; set; }
  
      [Required(ErrorMessage = "Please Enter Religion")]
      public string Religion { get; set; }
  
      [Required(ErrorMessage = "Please Enter TaxAddress")]
      public string TaxAddress { get; set; }
  
      [Required(ErrorMessage = "Please Enter Home Address")]
      public string HomeAddress { get; set; }
  
      [Required(ErrorMessage = "Please Enter Current Address")]
      public string CurrentAddress { get; set; }
  
      [Required(ErrorMessage = "Please Enter Phone Number")]
      public string PhoneNumber { get; set; }
  
      [Required(ErrorMessage = "Please Enter Email")]
      public string Email { get; set; }
  
      [Required(ErrorMessage = "Please Enter IsAuditor")]
      public string IsAuditor { get; set; }
  
      [Required(ErrorMessage = "Please Enter TaxProvince ")]
      public int TaxProvinceID { get; set; }
  
      [Required(ErrorMessage = "Please Enter Tax City ")]
      public int TaxCityID { get; set; }
  
      [Required(ErrorMessage = "Please Enter Home Province ")]
      public int HomeProvinceID { get; set; }
  
      [Required(ErrorMessage = "Please Enter Home City")]
      public int HomeCityID { get; set; }
  
      [Required(ErrorMessage = "Please Enter Current Province")]
      public int CurrentProvinceID { get; set; }
  
      [Required(ErrorMessage = "Please Enter Current City")]
      public int CurrentCityID { get; set; }
  
      [Required(ErrorMessage = "Please Enter Avatar Url")]
      public string AvatarUrl { get; set; }
  }
  </code></pre>
  
  <h1>Controller > EmployeesController</h1>
  
  <pre><code>    [HttpPost]
      public ActionResult Create(EventModel eventmodel, HttpPostedFileBase file)
      {
          if (ModelState.IsValid)
          {
              var filename = Path.GetFileName(file.FileName);
              var path = Path.Combine(Server.MapPath("~/Uploads/Photo/"), filename);
              file.SaveAs(path);
              tyre.Url = filename;
  
              _db.EventModels.AddObject(eventmodel);
              _db.SaveChanges();
              return RedirectToAction("Index");
          }
          return View(eventmodel);
      }
  </code></pre>