title: MVC Model Binding List of objects
body: <p>I am having trouble binding a model that contains list of objects. There are no problems when i try to pass the data from the controller to the view, but when i want to send the data back, i get a message that the method doesnt exists.</p>
  
  <p>I am using an ajax call and as data i put $form.serialize() and can see the list with all the data in fiddler, but i am having no luck with the binding.</p>
  
  <p>The Model is:</p>
  
  <pre><code>public class Single
  {
     public int Id {get;set;}
     public string Name {get;set;}
     public List&lt;SimpleDropdown&gt; dddl {get;set;}
     public int SelectedEmp {get;set;}
  }
  public class MainModel
  {
     public List&lt;Single&gt; main_model_list {get;set;}
  }
  </code></pre>
  
  <p>In my controller the method for now is:</p>
  
  <pre><code>[HttpPost]
  public string SaveModel(MainModel model)
  {
     return "";
  }
  </code></pre>
  
  <p>This method doesn't get called, but when i remove the parameter the calling works. So i'm sure that the binding doesn't work. I had a lot more complex model, but i simplified it as much as i can and still couldn't get it to work. </p>
  
  <p>So my question is how can i test this to see what is the problem?</p>
  
  <p>Edit:</p>
  
  <p>I dont have the code at the moment, but that code is functional because i use it in other places in the project. It is something like this:</p>
  
  <pre><code>$("#form").submit(function( ) {
        $.ajax({
          url: "/Controller/SaveModel",
          type: "POST",
          data: $(this).serialize()
      });
  });
  </code></pre>
  
  <p>The form looks something like this:</p>
  
  <pre><code>@using (Html.BeginForm("SaveModel", "Home", FormMethod.Post, new { id = "form" })) 
  {
      @for (var z = 0; z &lt; ViewBag.groupes.Length; z++)
      {
          &lt;div style="border-left: 1px solid black"&gt;
              &lt;h1&gt;@ViewBag.groupes[z]&lt;/h1&gt;
          &lt;/div&gt;
      }
      @for (var i = 0; i &lt; Model.main_model_list.Count; i++)
      {
          &lt;div&gt;@Html.LabelFor(x =&gt; x.main_model_list[i].Id)&lt;/div&gt;
          &lt;div&gt;@Html.LabelFor(x =&gt; x.main_model_list[i].Name)&lt;/div&gt;
          &lt;div style="float: left"&gt;@Html.DropDownListFor(x =&gt; main_model_list[i].SelectedEmp, new SelectList(main_model_list[i].dddl, "Id", "Value", main_model_list[i].SelectedEmp), new { @class = "preferences_dd_lists" })&lt;/div&gt;
      }
  }
  </code></pre>