title: How to Update List<Model> with jQuery in MVC 4
body: <p>I am currently trying to create a settings page using a modified Index view. The goal is that the users get <em>all settings</em> displayed and can change <em>all settings within one view</em> and save <em>all settings using one single button</em>. The setting should be updated using Ajax.</p>
  
  <p><strong>My current approach:</strong></p>
  
  <p><em>View:</em></p>
  
  <pre><code>&lt;script language="javascript"&gt;
      $(function() {
          $('#editSettings').submit(function () {
              if ($(this).valid()) {
                  $.ajax({
                      url: this.action,
                      type: this.method,
                      data: $(this).serialize(),
                      success: function (result)
                      {
                          alert(result);                       
                      }
                  });
              }
              return false;
          });
      });
  &lt;/script&gt;
  
  [ ... ]
  
  @using (Ajax.BeginForm("Edit", "Settings", new AjaxOptions {UpdateTargetId = "result"}, new { @class = "form-horizontal", @id = "editSettings" } ))
  {
      foreach (Setting item in ViewBag.Settings) 
      {
          @Html.Partial("_SingleSetting", item)
      }
      &lt;input type="submit" value="modify" /&gt;
  }
  </code></pre>
  
  <p><em>Partial View to load the setting:</em></p>
  
  <pre><code>        &lt;div class="control-group"&gt;
              &lt;label class="control-label"&gt;@settingName&lt;/label&gt;
              &lt;div class="controls"&gt;
                  @Html.EditorFor(model =&gt; model.Value)
                  &lt;span class="help-inline"&gt;@settingDescription&lt;/span&gt;
              &lt;/div&gt;
          &lt;/div&gt;
  </code></pre>
  
  <p><em>Model:</em></p>
  
  <pre><code>[Table("Settings")]
  public class Setting
  {
      [Key]
      [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
      public int SettingId { get; set; }
  
      public string Name { get; set; }
  
      [Required(AllowEmptyStrings = true)]
      [DisplayFormat(ConvertEmptyStringToNull = false)]
      public string Value { get; set; }
  }
  </code></pre>
  
  <p>I am setting the ViewBag using <code>ViewBag.Settings = _db.Settings.ToList();</code></p>
  
  <p>The jQuery parses the Data to the following method:</p>
  
  <pre><code>    [HttpPost]
      public ActionResult Edit(IList&lt;Setting&gt; setting)
      {
          Console.WriteLine(setting.Count);
          return Content(""); // Currently for testing purposes only. Breakpoint is set to setting.Count
      }
  </code></pre>
  
  <p><code>Count</code> throws an error because setting is <code>null</code>. I am quite unsure how to fix this problem. </p>
  
  <p>Can someone can give me a hint?</p>
  
  <p><a href="https://stackoverflow.com/questions/7419742/how-to-updating-ienumerablemyobject-in-mvc">This</a> topic on SO already covers updating a Collection without Ajax. But I won't get the point.</p>
  
  <p>Thank you for your help.</p>