我使用jquery删除了mvc 4中的操作。如果我单击删除按钮,我只为特定列设置Isactive = 0。
Jquery的
$('.btnDelete').live("click", function () {
var didconfirm = confirm("Are you sure ?");
debugger;
if (didconfirm == true)
{
var emaildata = $(this).closest('td').siblings(':first-child').text();
$.ajax({
type: "post",
url: "/Home/delete",
contentType: "application/json; chatset=utf-8",
//data: "{ 'EmailId' : '" + $(this).attr("data-member") + "'}",
data: "{ 'EmailId' : '" + emaildata + "'}",
confirm: "Need to delete this",
onSuccess: "deleteConfirmation",
success: function (data) {
alert("Record deleted Successfully");
}
});
}
});
行动守则
[HttpPost]
public ActionResult delete(string EmailId)
{
var linq = (from db in userobject.UserTables
where EmailId==db.EmailId
select db).FirstOrDefault();
if (linq.EmailId == EmailId)
{
linq.IsActive = false;
UpdateModel(linq);
userobject.SaveChanges();
}
return RedirectToAction("Home");
}
这个opeartion工作正常但我的页面显示相同的记录,而我点击其他一些功能。如何点击删除功能删除已删除的记录。提前谢谢。
答案 0 :(得分:0)
在您的成功功能中,从表中删除已删除的tr(假设每个表行中都有一个删除按钮):
$('.btnDelete').live("click", function () {
var $tr = $(this).closest('tr');
...
$.ajax({
...
success: function (data) {
$tr.remove();
alert("Record deleted Successfully");
}
答案 1 :(得分:0)
试试这个,
您必须为表行创建动态ID,然后简单。
$.ajax({
type: "post",
url: "/Home/delete",
contentType: "application/json; chatset=utf-8",
//data: "{ 'EmailId' : '" + $(this).attr("data-member") + "'}",
data: "{ 'EmailId' : '" + emaildata + "'}",
confirm: "Need to delete this",
onSuccess: "deleteConfirmation",
success: function (data) {
//when removed from DB.
$("#dynamic_row_id").remove();
}
});
答案 2 :(得分:0)
您可以从$(this)对象中找到父tr(我假设您的按钮位于td元素中),然后在成功回调后将其删除。
$('.btnDelete').live("click", function () {
var didconfirm = confirm("Are you sure ?");
debugger;
if (didconfirm == true)
{
var emaildata = $(this).closest('td').siblings(':first-child').text();
var curRow = $(this).parent('tr');
$.ajax({
type: "post",
url: "/Home/delete",
contentType: "application/json; chatset=utf-8",
//data: "{ 'EmailId' : '" + $(this).attr("data-member") + "'}",
data: "{ 'EmailId' : '" + emaildata + "'}",
confirm: "Need to delete this",
onSuccess: "deleteConfirmation",
success: function (data) {
alert("Record deleted Successfully");
curRow.remove();
}
});
}
});