C# 显示从网格中删除记录的确认消息
当用户从网格中删除记录时,我想显示一条确认消息。这是我实现的,但我有错误消息 使用下面的代码,记录将被删除,但:C# 显示从网格中删除记录的确认消息,c#,jquery,asp.net,asp.net-mvc,asp.net-mvc-4,C#,Jquery,Asp.net,Asp.net Mvc,Asp.net Mvc 4,当用户从网格中删除记录时,我想显示一条确认消息。这是我实现的,但我有错误消息 使用下面的代码,记录将被删除,但: 记录仍在网格中,我必须刷新才能看到它消失 我有消息错误!即使记录被删除 三, 控制器: public ActionResult DeleteRecord(string StudentID) { //Code to delete } return RedirectToAction("StudentGrid",
public ActionResult DeleteRecord(string StudentID)
{
//Code to delete
}
return RedirectToAction("StudentGrid",
"Home");
}
在不查看正在使用的网格的情况下,请尝试以下操作: 获取最接近的tr标记,以便在成功删除时使用:
var $tr = $(this).closest("tr");
$tr.remove();
设置来自控制器的内容消息,重定向将无法工作,因为它是一个ajax调用
public ActionResult DeleteRecord(string StudentID)
{
var success = false;
//Code to delete
// then set success variable
if (success)
{
return Content("Deleted");
}
else
{
return Content("Failed");
}
}
然后,从成功处理程序中检查消息,并在需要时删除,客户端代码将如下所示:
function OnDeleteClick(e)
{
e.preventDefault();
var $tr = $(this).closest("tr");
var StudentId = e.target.id;
var flag = confirm('You are about to delete this record permanently. Are you sure you want to delete this record?');
if (flag) {
$.ajax({
url: '/Home/DeleteRecord',
type: 'POST',
data: { StudentID: StudentId },
dataType: 'json',
success: function (result) {
if (result == "Deleted")
$tr.remove();
},
error: function () {
alert('Error!');
}
});
}
return false;
}
在不查看正在使用的网格的情况下,请尝试以下操作: 获取最接近的tr标记,以便在成功删除时使用:
var $tr = $(this).closest("tr");
$tr.remove();
设置来自控制器的内容消息,重定向将无法工作,因为它是一个ajax调用
public ActionResult DeleteRecord(string StudentID)
{
var success = false;
//Code to delete
// then set success variable
if (success)
{
return Content("Deleted");
}
else
{
return Content("Failed");
}
}
然后,从成功处理程序中检查消息,并在需要时删除,客户端代码将如下所示:
function OnDeleteClick(e)
{
e.preventDefault();
var $tr = $(this).closest("tr");
var StudentId = e.target.id;
var flag = confirm('You are about to delete this record permanently. Are you sure you want to delete this record?');
if (flag) {
$.ajax({
url: '/Home/DeleteRecord',
type: 'POST',
data: { StudentID: StudentId },
dataType: 'json',
success: function (result) {
if (result == "Deleted")
$tr.remove();
},
error: function () {
alert('Error!');
}
});
}
return false;
}
通过控制器的is响应,您可以在警报()中显示此消息
有了项目中的更新网格,您可以使用下面的代码就足够了
$(e).closest("tr").remove();
通过控制器的is响应,您可以在警报()中显示此消息
有了项目中的更新网格,您可以使用下面的代码就足够了
$(e).closest("tr").remove();
我正在使用GridMVC,您的代码用于消息,但网格不是refreshed@melom对不起,我不知道如何刷新GridMVC。我想提出另一个问题,就是关于这个问题。有人会很快回答我,我肯定,我已经很久没用过了。:)我正在使用GridMVC,您的代码用于消息,但网格不是refreshed@melom对不起,我不知道如何刷新GridMVC。我想提出另一个问题,就是关于这个问题。有人会很快回答我,我肯定,我已经很久没用过了。:)