当选中或取消选中复选框时,我试图更新我的数据库。我希望它在单击复选框时更新。这是我到目前为止所拥有的,但我的控制器从未被击中。我能做什么来修复它?理想情况下,我想将 customer.IsDone 和 customer.Id 的新值传递给我的控制器,但我不知道如何执行此操作。
在我看来复选框
<td>@Html.CheckBoxFor(m => customer.IsDone, new { onclick = "UpdateCustomer(IsDone)" })</td>
Run Code Online (Sandbox Code Playgroud)
我认为的功能
function UpdateCustomer(isDone) {
$.ajax({
type: 'POST',
url: @Url.Action("UpdateCustomer", "Home"),
data: { check: isDone },
success: success,
dataType: 'json'
});
}
Run Code Online (Sandbox Code Playgroud)
这是我的控制器方法
[HttpPost]
public ActionResult UpdateCustomer(bool check)
{
//code will be here to update the db
var customers = new CustomerGetAll();
var list = customers.Execute();
return View("Customers", list);
}
Run Code Online (Sandbox Code Playgroud)