title: ASP.NET MVC5 HttpPostedFileBase always returning null
body: <p>I have looked up many similar questions but to no avail. Solutions range from ensuring the <em>name</em> of the input field is same as the param, and including <em>multipart/form-data.</em> When POSTing, the image is always returning null.</p>
  
  <p><strong><em>Confirm.cshtml</em></strong></p>
  
  <pre><code>@model IQueryable&lt;SGHealthDesktop.Models.Patient&gt;
  
  @using (Html.BeginForm("Confirm", "Doctor", new { enctype = "multipart/form-data", guid = Model.First().PatientId }, FormMethod.Post, null)) {
                      @Html.AntiForgeryToken()
  
                      &lt;div class="form-horizontal"&gt;
                          @Html.ValidationSummary(true, "", new { @class = "text-danger" })
                          @if (Model != null) {
  
                              &lt;div class="form-group"&gt;
                                  @Html.LabelFor(model =&gt; model.First().PatientName, htmlAttributes: new { @class = "control-label col-md-2" })
                                  &lt;div class="col-md-10"&gt;
                                      @Html.EditorFor(model =&gt; model.First().PatientName, new { htmlAttributes = new { @class = "form-control", disabled = "disabled" } })
                                  &lt;/div&gt;
                              &lt;/div&gt;
  
                              &lt;div class="form-group"&gt;
                                  @Html.LabelFor(model =&gt; model.First().UniqueId, htmlAttributes: new { @class = "control-label col-md-2" })
                                  &lt;div class="col-md-10"&gt;
                                      @Html.EditorFor(model =&gt; model.First().UniqueId, new { htmlAttributes = new { @class = "form-control", disabled = "disabled" } })
                                  &lt;/div&gt;
                              &lt;/div&gt;
  
                              &lt;div class="form-group"&gt;
                                  @Html.LabelFor(model =&gt; model.First().Evidence, htmlAttributes: new { @class = "control-label col-md-2" })
                                  &lt;div class="col-md-10"&gt;
                                      @Html.TextBoxFor(model =&gt; model.First().Evidence, new { type = "file", name = "uploadFile", id = "uploadFile", required = "required", @class = "form-control" })
                                  &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="Request" class="btn btn-success" /&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                          }
                      &lt;/div&gt;
                  }
  </code></pre>
  
  <p><strong><em>DoctorController.cs</em></strong></p>
  
  <pre><code>// POST: Doctor/Confirm
          [HttpPost, ActionName("Confirm")]
          [ValidateAntiForgeryToken]
          public ActionResult Confirmed(string guid, HttpPostedFileBase uploadFile) {
              try {
                  if (ModelState.IsValid) { // to be binded later. 
                      ImageService imageService = new ImageService();
                      var imageUrl = imageService.UploadImage(UploadedFile);
  
                      var currentTime = DateTime.Now;
  
                      db.Appeal.Add(new Appeal {
                          DoctorId = User.Identity.GetUserId(),
                          PatientId = guid,
                          Evidence = imageUrl,
                          Time = currentTime, 
                          IsApprove = false
                      });
                      TempData["Message"] = "Appeal is being processed. Check the Request page for outcome.";
                      db.SaveChanges();
                      return RedirectToAction("Index");
                  } else {
                      var errors = ModelState.Values.SelectMany(v =&gt; v.Errors);
                  }
              } catch (DataException dex) {
              }
              return RedirectToAction("Patient");
          }
  </code></pre>
  
  <p>May I know where did I go wrong?</p>
  
  <p><strong>Update</strong></p>
  
  <pre><code>// GET: Doctor/Confirm
          public ActionResult Confirm(string id) {
  
              if (string.IsNullOrEmpty(id)) {
                  return View("Error");
              }
  
              IQueryable&lt;Patient&gt; nameQuery = (from user in db.Users
                                               where user.Id.Equals(id)
                                               select new Patient {
                                                   PatientId = user.Id,
                                                   PatientName = user.FullName,
                                                   UniqueId = user.UniqueId
                                               });
              if (nameQuery == null) {
                  return HttpNotFound();
              }
              return View(nameQuery);
          }
  </code></pre>