如何解决使用 Jquery 删除在 Linq to sql 中不起作用?
// 控制器代码
[HttpPost]
public JsonResult Delete(Int32 id)
{
// TODO: Add delete logic here
TendorList t1 = db.TendorLists.Where(x => x.CompanyId == id).FirstOrDefault();
db.TendorLists.DeleteOnSubmit(t1);
db.SubmitChanges();``
return Json(true,JsonRequestBehavior.AllowGet);
}
// Jquery 代码
$("body").on("click","#tblStudent .Delete",function () {
if (confirm("Do you want to delete this row?")) {`enter code here`
var row = $(this).closest("tr");
var CompanyId = row.find("span").html();
$.ajax({
type: "POST",url: "/Tendor/Delete",data: '{CompanyId: ' + CompanyId + '}',contentType: "application/json; charset=utf-8",dataType: "json",success: function (response) {
row.remove();
}
});
}
});
解决方法
您将 id 作为 CompanyId 发送,但在后面的代码中,您尝试将其作为 Id 捕获。 您应该将帖子数据更新为数据:'{id: ' + CompanyId + '}',
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。