【发布时间】:2021-03-07 17:37:54
【问题描述】:
如果我将 AJAXEditIsDoneCheckBox 更改为 Edit,代码将不起作用,这是为什么?代码无需更改即可正常工作,但我想知道问题所在。我将不胜感激。
控制器
[HttpPost]
public ActionResult AJAXEditIsDoneCheckBox(int? id, bool value)
{
if (id == null)
{
return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
}
ToDo toDo = db.ToDos.Find(id);
if (toDo == null)
{
return HttpNotFound();
}
else
{
toDo.IsDone = value;
db.Entry(toDo).State = EntityState.Modified;
db.SaveChanges();
return PartialView("_ToDoTable", GetToDoes());
}
}
脚本
$(document).ready(function () {
$('.ActiveCheck').change(function () {
var self = $(this);
var id = self.attr('id');
var value = self.prop('checked');
$.ajax({
url: '/ToDoes/EditIsDoneCheckBox',
data: {
id: id,
value: value
},
type: 'POST',
success: function (result) {
$('#tableDiv').html(result);
}
});
});
});
查看
@Html.CheckBoxFor(modelItem => item.IsDone, new { id = item.Id, @class = "ActiveCheck" })
【问题讨论】:
-
“代码不工作” - 哪个部分不工作?
标签: c# ajax asp.net-mvc