c# - 使用 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 捕获。您应该将您的帖子数据更新为 data: '{id: ' + CompanyId + '}',
推荐阅读
- javascript - 语义 UI 模态高度太长
- string - 使用 Lua 匹配整个精确的文本行
- reactjs - React Native Image Picker 不运行任何 ImagePicker 函数?
- typescript - 将 gatsby-plugin-typescript 添加到 GatsbyJS “React 未定义”
- java - 简单的 Spring Boot 应用程序中使用了哪个 ApplicationContext 实现?
- php - 正则表达式:将单个等号与负前瞻匹配 =
- wordpress - wp-api cookie 身份验证 wpApiSettings 未定义
- excel - 第一次返回 test 为 true 的行的函数,然后是第二次,然后是第三次等
- javascript - 无法访问 Electron 渲染器进程中的某些 DOM 方法
- netsuite - Netsuite SuiteCloud IDE 如何将管理员用户设置为没有双重身份验证