title: Posting Form to Partial View via AJAX
body: <p>I am trying to post data from a partial view form (viewbag) to an action method on the main controller. I am using Jquery:</p>
  
  <pre><code>$.ajax({
      url: '@Url.Action("displaypreviewformactionmethod", "MyMainController")',
      type: 'post',
      dataType: 'json',
      data: $('form#realform').serialize(),
      success: function (data) {
          $('#DivTagWhereMyPartialViewIs').html(data);
          $('#DivTagWhereMyPartialViewIs').show();
      }
  </code></pre>
  
  <p>My Partial View with the Form looks like:</p>
  
  <pre><code>&lt;div id="step-3" class=""&gt;
      @using (Html.BeginForm("displaypreviewformactionmethod", "MyMainController"))
      {
          foreach (var frm in Model)
          {
              &lt;tr&gt;
                  &lt;td&gt;
                      @Html.LabelFor(model =&gt; model.FirstOrDefault().ELabel, frm.SomeText)
                  &lt;/td&gt;
                  &lt;td&gt;
                      @Html.TextBox(frm.FieldName)&lt;br /&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
          }
          &lt;input type="submit" name="Submit" value="Submit" /&gt;
      }
  &lt;/div&gt;
  </code></pre>
  
  <p>The action method in the main controller is:</p>
  
  <pre><code>public ActionResult displaypreviewformactionmethod(FormCollection form)
  {
      if (form.Count &gt; 0)
      {
          ViewBag.FormItems = form;
      }
      return PartialView("MyPartialView", form);
  }
  </code></pre>
  
  <p>The action gets called, but it doesn't pass anything in the formcollection to the partial view- which leads me to believe that I'm not correctly identifying the form in the partial view. I tried adding <code>&lt;form id="realform"&gt;</code> before the  in the partial view but that didn't work. Is there some other way I can identify the form in Jquery?</p>
  
  <p>Any direction much appreciated.</p>