title: Posting back a dynamic list model to controller using AJAX and javascript
body: <p>I have a partial view that displays in a jquery modal popup window. The view is made up of a dynamically generated list of checkboxes and can contain one to many checkboxes. I am having a problem with trying to post the model back to the controller. The model is a generic list(of T)</p>
  
  <p>Below is the controller action:</p>
  
  <pre><code>   &lt;HttpPost&gt;
      Function CertBodiesListPostBack(ByVal Model As List(Of DataModels.DataModels.CertBodyVM)) As JsonResult
          ViewBag.CourseId = Model(0).courseId
          Data_Manager.CertifyBody.SaveCertBody(Model(0).courseId, Model)
          Return Json(New With {.success = True})
      End Function
  </code></pre>
  
  <p>and the view view is like this:</p>
  
  <pre><code> @Modeltype List(Of DataModels.CertBodyVM)
   @Code
  
   End Code
  &lt;link href="@Url.Content("~/Content/jquery-ui-1.10.3.custom.css")" rel="stylesheet" type="text/css" /&gt;
  &lt;script type="text/javascript"&gt;
     $(document).ready(function () {
      $("#btnUpdate").click(function () {
          $('#waitMessage').show();
  
          $.ajax({
              url: '@Url.Action("CertBodiesListPostBack", "Admin")',
              type: 'POST',
              data: JSON.stringify('@model'),
              dataType: "json",
              context: $(this),
              success: function (result) {
  
                  $('#waitMessage').hide();
                  $("#dialog-edit").dialog().dialog('close');
  
              },
              error: function (result) {
                  alert('There was an error processing the request!!');
  
              }
          });
          return false;
      });
     });
   &lt;/script&gt;
  &lt;style&gt;
   #waitMessage {
  
    background:  url('../../Content/Images/animated-processing.gif')  scroll no-repeat center;
    height: 100px; width: 100px;
    position: fixed; left: 50%; top: 50%; z-index: 1000;
    margin: -25px 0 0 -25px;
    }
   &lt;/style&gt;
   &lt;div id="waitMessage" class="dataContainer" style="display: none;"&gt;
    &lt;p&gt;Saving Note&lt;/p&gt;
   &lt;/div&gt;
   @Using Html.BeginForm()
   @&lt;fieldset&gt;&lt;legend&gt;&lt;/legend&gt;
  
   &lt;table&gt;
      &lt;tr&gt;
      &lt;th&gt;Certifying Bodies&lt;/th&gt;
      &lt;/tr&gt;
   @For i As Integer = 0 To Model.Count - 1
           Dim y As Integer = i
           Dim d As String = Model(y).certName
       @&lt;tr&gt;&lt;td style="text-align: left"&gt;@Html.CheckBoxFor(Function(model) model(y).certSelected)@Html.Label(d)@Html.HiddenFor(Function(model) model(y).certBodyId)@Html.HiddenFor(Function(model) model(y).courseId)&lt;/td&gt;&lt;/tr&gt;
     Next
  
     &lt;/table&gt;
     &lt;input type="button" value="Save" id="btnUpdate" name="cmd" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" /&gt;
  
      &lt;input type="button" value="Cancel" id="btncancel" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" /&gt;
      &lt;/fieldset&gt;   
  
      End Using
  </code></pre>
  
  <p>And the model is as Follows:</p>
  
  <pre><code>    Public Class CertBodyVM
      Private _certName As String
      Public Property certName() As String
          Get
              Return _certName
          End Get
          Set(ByVal value As String)
              _certName = value
          End Set
      End Property
      Private _certSelected As Boolean
      Public Property certSelected() As Boolean
          Get
              Return _certSelected
          End Get
          Set(ByVal value As Boolean)
              _certSelected = value
          End Set
      End Property
      Private m_certBodyId As Integer
      Public Property certBodyId() As Integer
          Get
              Return m_certBodyId
          End Get
          Set(ByVal value As Integer)
              m_certBodyId = value
          End Set
      End Property
      Private m_CourseId As Integer
      Public Property courseId() As Integer
          Get
              Return m_CourseId
          End Get
          Set(ByVal value As Integer)
              m_CourseId = value
          End Set
      End Property
  End Class
  </code></pre>
  
  <p>I am new to javascript and AJAX so </p>