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: Ajax.ActionLink(...) with checkbox Here is my code in the cshtml file:
@foreach (var item in Model) {
<tr>
<td>
@Html.DisplayFor(modelItem => item.Macro_Name)
</td>
<td>
@Html.CheckBoxFor(modelItem => item.Claimed, new { id = item.Macro_Name, data_url = Url.Action("ToggleClaim", "MacroStatus")})
</td>
<td>
@Html.DisplayFor(modelItem => item.Date_Claimed)
</td>
<td>
@Html.DisplayFor(modelItem => item.Username)
</td>
<td>
@Html.DisplayFor(modelItem => item.Finished)
</td>
<td>
@Html.DisplayFor(modelItem => item.Date_Completed)
</td>
<td>
@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 })
</td>
</tr>
}
In the MacroStatusController class I have the following action:
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);
}
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?