title: How can I pass values from a view to a controller without using a form field?
body: <p>I have a view that is a page for uploading files. This view calls a controller that needs a name passed into it as well as a list of the file names. I am able to pass in the list of file names just fine but I dont know how I can pass the customer name from my view back to my controller. I dont want to have a random textbox since I want to use the specific value already in Model.customerName. </p>
  
  <p>Controller</p>
  
  <pre><code>public ActionResult UploadFiles(Customer customer)
  {
       FileModel fileModel = new FileModel();
       fileModel.customerName = customer.Name;
  
       return View(fileModel);
  }
  
  [HttpPost]
  public ActionResult UploadFiles(HttpPostedFileBase[] files)
  {
        foreach (HttpPostedFileBase file in files)
        {
            if (file != null)
            {
                var ServerSavePath = Path.Combine(Server.MapPath("~/Files/") + file.FileName);
                file.SaveAs(ServerSavePath);
  
                //upload to sharepoint
                UploadFileToSharePoint(ServerSavePath);
  
                ViewBag.UploadStatus = files.Length.ToString() + " files uploaded successfully.";
            }
        }
  
      return View();
  }
  </code></pre>
  
  <p>View</p>
  
  <pre><code>@model Models.FileModel
  
  @if (Model.customerName != null)
  {
      &lt;h2&gt;@Model.customerName&lt;/h2&gt;
  }
  
  @using (Html.BeginForm("UploadFiles", "Home", FormMethod.Post, new { enctype = "multipart/form-data" }))
  { 
      @Html.AntiForgeryToken()
  
      &lt;div class="form-horizontal"&gt;
          &lt;hr /&gt;
          @Html.ValidationSummary(true, "", new { @class = "text-danger" })
          &lt;div class="form-group"&gt;
              @Html.LabelFor(model =&gt; model.files, htmlAttributes: new { @class = "control-label col-md-2" })
              &lt;div class="col-md-10"&gt;
                  @Html.TextBoxFor(model =&gt; model.files, "", new { @type = "file", @multiple = "multiple" })
                  @Html.ValidationMessageFor(model =&gt; model.files, "", new { @class = "text-danger" })
              &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="Upload" class="btn btn-primary" /&gt;
              &lt;/div&gt;
          &lt;/div&gt;
          &lt;div class="form-group"&gt;
              &lt;div class="col-md-offset-2 col-md-10 text-success"&gt;
                  @ViewBag.UploadStatus
              &lt;/div&gt;
          &lt;/div&gt;
  
      &lt;/div&gt;
  }
  &lt;script src="~/Scripts/jquery-1.10.2.min.js"&gt;&lt;/script&gt;
  &lt;script src="~/Scripts/jquery.validate.min.js"&gt;&lt;/script&gt;
  &lt;script src="~/Scripts/jquery.validate.unobtrusive.min.js"&gt;&lt;/script&gt;  
  </code></pre>
  
  <p>I tried passing it in after the enctype = "multipart/form-data", but it appeared as null in my controller.</p>
  
  <p><strong>UPDATE:</strong>
  I ended up using a hidden field in my view. </p>
  
  <pre><code>@Html.HiddenFor(m =&gt; m.customerName, new {Value = Model.customerName})
  </code></pre>
  
  <p>And in my controller I had to grab the FormCollection</p>
  
  <pre><code>public ActionResult UploadFiles(System.Web.Mvc.FormCollection fc, 
  HttpPostedFileBase[] files)
  {
        string customerName = fc["customerName"];
        ...
  }
  </code></pre>