title: IFormFile Upload Image ASP.NET core MVC
body: <p>Sorry to bother you guys but i have a problem that i have no idea how to solve and i have been browsing for days now and trying different solution.</p>
  
  <p>So i am building a website where i want to implement a user section when the User can Upload his personal image as picture Profile.</p>
  
  <p>And here is where the problem i raise, when i run the code, it return always as null.</p>
  
  <p>Here is my Controller:</p>
  
  <pre><code>[HttpPost]
      public async Task&lt;IActionResult&gt; Create(EmployeeCreateViewModel model)
      {
  
          if (ModelState.IsValid)
          {
  
  
              string uniqueFileName = null;
              if(model.Photo != null)
              {
                  string uploadsFolder = Path.Combine(_hostingEnvironment.WebRootPath, "EmpImg");
                  uniqueFileName = Guid.NewGuid().ToString() + "_" + model.Photo.FileName;
                  using(var fs = new FileStream(Path.Combine(uploadsFolder, uniqueFileName), FileMode.Create))
                  {
                      await model.Photo.CopyToAsync(fs);
                  }
  
  
              }
              Employee newEmployee = new Employee
              {
                  Name = model.Name,
                  Surname = model.Surname,
                  Email = model.Email,
                  Area = model.Area,
                  PhotoPath = uniqueFileName
              };
              _employeeRepository.Add(newEmployee);
              return RedirectToAction("details", new { id = newEmployee.Id });
          }
  
          return View();
  
      }
  </code></pre>
  
  <p>And this is my View</p>
  
  <pre><code>&lt;form enctype="multipart/form-data" asp-controller="Employee" asp-action="create" method="post"&gt;
  
      &lt;div class="form-group row"&gt;
          &lt;label asp-for="Name" class="col-sm-2 col-form-label"&gt;&lt;/label&gt;
          &lt;div class="col-sm-10"&gt;
              &lt;input asp-for="Name" class="form-control" placeholder="Name..." /&gt;
              &lt;span asp-validation-for="Name" class="text-danger"&gt;&lt;/span&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group row"&gt;
          &lt;label asp-for="Surname" class="col-sm-2 col-form-label"&gt;&lt;/label&gt;
          &lt;div class="col-sm-10"&gt;
              &lt;input asp-for="Surname" class="form-control" placeholder="Surname..." /&gt;
              &lt;span asp-validation-for="Surname" class="text-danger"&gt;&lt;/span&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="form-group row"&gt;
          &lt;label asp-for="Email" class="col-sm-2 col-form-label"&gt;&lt;/label&gt;
          &lt;div class="col-sm-10"&gt;
              &lt;input asp-for="Email" class="form-control" placeholder="Email..." /&gt;
              &lt;span asp-validation-for="Email" class="text-danger"&gt;&lt;/span&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group row"&gt;
          &lt;label asp-for="Area" class="col-sm-2 col-form-label"&gt;Location:&lt;/label&gt;
          &lt;div class="col-sm-10"&gt;
              &lt;select asp-for="Area" class="custom-select mr-sm-2" asp-items="Html.GetEnumSelectList&lt;Area&gt;()"&gt;
                  &lt;option value=""&gt;Please Select..&lt;/option&gt;
              &lt;/select&gt;
              &lt;span asp-validation-for="Area" class="text-danger"&gt;&lt;/span&gt;
  
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="form-group row"&gt;
          &lt;label asp-for="Photo" class="col-sm-2 col-form-label"&gt;&lt;/label&gt;
          &lt;div class="col-sm-10"&gt;
              &lt;div class="custom-file"&gt;
                  &lt;input asp-for="Photo" name="Create" class="form-control custom-file-input" /&gt;
                  &lt;label class="custom-file-label"&gt;Choose File...&lt;/label&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div asp-validation-summary="All" class="text-danger"&gt;&lt;/div&gt;
      &lt;div class="form-group row"&gt;
          &lt;div class="col-sm-2"&gt;
              &lt;button type="submit" class="btn btn-primary"&gt;Create&lt;/button&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      @section Scripts {
      &lt;script&gt;
          $(document).ready(function () {
              $('.custom-file-input').on("change", function () {
                  var fileName = $(this).val().split("\\").pop();
                  $(this).next('.custom-file-label').html(fileName);
              });
          });
      &lt;/script&gt;
      }
  &lt;/form&gt;
  </code></pre>
  
  <p>When i try To upload the img in the browser it doesnt Throw any exeption, it just doesnt Upload the image to the database and the column is NULL.</p>
  
  <p>thank you in advance to everybody for any help or advice.</p>