title: Send ASP.NET MVC HttpContext to Web Api HttpContext
body: <p>I'm trying to upload a file and I'd like to pass the current MVC HttpContext.Current.Request.Files to a Web API.</p>
  
  <p>I tried to pass the <code>HttpFileCollectionBase</code> as parameter to pass it to the API but it's always null.
  <strong>Controller</strong></p>
  
  <pre><code>public object UploadAttachment(string param1, int param2, HttpFileCollectionBase files)
  {
     string _url = _restUrl + param1+ "/Folders/" + param2+ "/UploadAttachment";
     HttpResponseMessage _response = SendJsonRequest(_url, HttpMethod.Post, files);
     var ret = DeserializeResponse(_response);
     return ret;
  }
  </code></pre>
  
  <p><strong>API code</strong>:</p>
  
  <pre><code>[HttpPost]
  [Route("Archives/{param1}/Folders/{param2}/UploadAttachment")]      
  public IHttpActionResult UploadAttachment([FromUri]string param1, [FromUri]int param2, [FromBody] HttpFileCollectionBase files)
  </code></pre>
  
  <p><strong>View Code</strong></p>
  
  <pre><code>using (Ajax.BeginForm("UploadAttachment", null, new { param1 = Model.Param1 }, new AjaxOptions { HttpMethod = "POST", OnSuccess = "uploadAttachmentSuccess" }, new { id = "uploadAttachment", enctype = "multipart/form-data" }))
                      {
                      &lt;div class="row"&gt;
                          &lt;div class="col-xs-10"&gt;
                              &lt;div class="input-group"&gt;
                                  &lt;label class="input-group-btn" title=""&gt;
                                      &lt;span class="btn btn-primary"&gt;
                                          &lt;input type="file" name="file_upload" id="file_upload" style="display: none;" multiple /&gt;
                                          Browse
                                      &lt;/span&gt;
                                  &lt;/label&gt;
                                  &lt;input type="text" id="file_upload_name" class="form-control" readonly&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class="col-xs-2"&gt;
                              &lt;button type="submit" class="btn btn-success" data-toggle="tooltip" id="btn-submit-upload" title="" disabled&gt;
                                  Upload
                              &lt;/button&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                      &lt;div class="row"&gt;
                          &lt;div class="col-xs-12" id="warning-format"&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                      }
  </code></pre>
  
  <p><strong>SendJsonRequest Implementation</strong></p>
  
  <pre><code>            protected virtual HttpResponseMessage SendJsonRequest(string url, HttpMethod method, object objectToSerialize = null, bool tryToRefreshToken = true)
      {
          ...
          HttpRequestMessage _request = new HttpRequestMessage(method, _uri);
          if (objectToSerialize != null)
          {
              string _serializedJSONObject = JsonConvert.SerializeObject(objectToSerialize);
              _request.Content = new StringContent(_serializedJSONObject);
              _request.Content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
          }...
  </code></pre>