title: How can I make an asp.net mvc checkbox trigger an action?
body: <p>I would like to update the database when someone checked a box that represents a bit field on the row.  I have been going off of this question: <a href="https://stackoverflow.com/questions/11139920/ajax-actionlink-with-checkbox">Ajax.ActionLink(...) with checkbox</a>
  Here is my code in the cshtml file:</p>
  
  <pre><code>@foreach (var item in Model) {
  &lt;tr&gt;
      &lt;td&gt;
          @Html.DisplayFor(modelItem =&gt; item.Macro_Name)
      &lt;/td&gt;
      &lt;td&gt;
          @Html.CheckBoxFor(modelItem =&gt; item.Claimed, new { id = item.Macro_Name, data_url = Url.Action("ToggleClaim", "MacroStatus")})
      &lt;/td&gt;
      &lt;td&gt;
          @Html.DisplayFor(modelItem =&gt; item.Date_Claimed)
      &lt;/td&gt;
      &lt;td&gt;
          @Html.DisplayFor(modelItem =&gt; item.Username)
      &lt;/td&gt;
      &lt;td&gt;
          @Html.DisplayFor(modelItem =&gt; item.Finished)
      &lt;/td&gt;
      &lt;td&gt;
          @Html.DisplayFor(modelItem =&gt; item.Date_Completed)
      &lt;/td&gt;
      &lt;td&gt;
          @Html.ActionLink("Edit", "Edit", new { id=item.Macro_Name }) |
          @Html.ActionLink("Details", "Details", new { id = item.Macro_Name }) |
          @Html.ActionLink("Delete", "Delete", new { id = item.Macro_Name })
      &lt;/td&gt;
  &lt;/tr&gt;
  }
  </code></pre>
  
  <p>In the MacroStatusController class I have the following action:</p>
  
  <pre><code>    public ActionResult ToggleClaim(string id)
      {
          if (id == null)
          {
              return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
          }
  
          MacroStatus macroStatus = db.MacroStatus1.Find(id);
          if (macroStatus == null)
          {
              return HttpNotFound();
          }
  
          if (ModelState.IsValid)
          {
              macroStatus.Date_Claimed = DateTime.Now;
              db.Entry(macroStatus).State = EntityState.Modified;
              db.SaveChanges();
          }
  
          return new HttpStatusCodeResult(HttpStatusCode.OK);
      }
  </code></pre>
  
  <p>However, ToggleClaim isn't running when I check or uncheck the box.  There are no compile errors.  This is my first try with asp.net mvc, what am I doing wrong?</p>