title: Post JSON data through a form in MVC4
body: <p>I'm trying to POST a JSON object (a JSON-ified knockout model, if that's of any relevance) to my MVC controller, and have the controller return a new view. To do this, I'm sending the data with a form. The problem is that I would like to have the JSON automatically converted to a model when the controller receives it. </p>
  
  <p>If I were to use an AJAX call for this,</p>
  
  <pre><code>var actionModel = new Object();
  actionModel.Controls = ko.toJS(self.controls());
  var json = JSON.stringify(actionModel);
  $.ajax({
      url: "MyController/Preview",
      type: "POST",
      contentType: 'application/json; charset=utf-8',
      cache: false,
      data: json,
      success: function (data) {
      }
  });
  </code></pre>
  
  <p>...the JSON object is successfully deserialized and converted into an instance of my model class.</p>
  
  <pre><code>public ActionResult Preview(ActionModel actionModel) { ... }
  public class ActionModel
  {
      public List&lt;ControlModel&gt; Controls { get; set; }
  }
  </code></pre>
  
  <p>If I want to do this with a form, I understand that I need to insert the JSON into a hidden input field, but the best I can manage when doing this is to receive the data as a serialized string:</p>
  
  <pre><code>@using (Html.BeginForm("Preview", "MyController", FormMethod.Post, new { id = "previewForm" }))
  {
      &lt;input type="hidden" id="hiddenFieldName" /&gt;
  }
  
  public ActionResult Preview(string hiddenFieldName) { ... }
  </code></pre>
  
  <p>I could just deserialize it afterwards, but I really would prefer it if MVC could convert it for me, as it would with an AJAX call. Is this possible?</p>
  
  <p>Thanks.</p>