title: ASP.NET MVC. How to create Action method that accepts and multipart/form-data
body: <p>I have a Controller method that needs to accept <code>multipart/form-data</code> sent by the client as a POST request. The form data has 2 parts to it. One is an object serialized to <code>application/json</code> and the other part is a photo file sent as <code>application/octet-stream</code>. I have a method on my controller like this:</p>
  
  <pre><code>[AcceptVerbs(HttpVerbs.Post)]
  void ActionResult Photos(PostItem post)
  {
  }
  </code></pre>
  
  <p>I can get the file via <code>Request.File</code> without problem here.However the PostItem is null.
  Not sure why? Any ideas</p>
  
  <p>Controller Code:</p>
  
  <pre><code>/// &lt;summary&gt;
  /// FeedsController
  /// &lt;/summary&gt;
  public class FeedsController : FeedsBaseController
  {
      [AcceptVerbs(HttpVerbs.Post)]
      public ActionResult Photos(FeedItem feedItem)
      {
          //Here the feedItem is always null. However Request.Files[0] gives me the file I need  
          var processor = new ActivityFeedsProcessor();
          processor.ProcessFeed(feedItem, Request.Files[0]);
  
          SetResponseCode(System.Net.HttpStatusCode.OK);
          return new EmptyResult();
      }
  </code></pre>
  
  <p>}</p>
  
  <p>The client request on the wire looks like this:</p>
  
  <pre><code>{User Agent stuff}
  Content-Type: multipart/form-data; boundary=8cdb3c15d07d36a
  
  --8cdb3c15d07d36a
  Content-Disposition: form-data; name="feedItem"
  Content-Type: text/xml
  
  {"UserId":1234567,"GroupId":123456,"PostType":"photos",
      "PublishTo":"store","CreatedTime":"2011-03-19 03:22:39Z"}
  
  --8cdb3c15d07d36a
  Content-Disposition: file; filename="testFile.txt"
  ContentType: application/octet-stream
  
  {bytes here. Removed for brevity}
  --8cdb3c15d07d36a--
  </code></pre>