Asp.net mvc 3 如何使用asp.net MVC的Jquery删除表中已删除的行
我有以下看法:-Asp.net mvc 3 如何使用asp.net MVC的Jquery删除表中已删除的行,asp.net-mvc-3,jquery,Asp.net Mvc 3,Jquery,我有以下看法:- <script type="text/javascript"> $(document).ready(function () { $("#removerow").click(function () { $(this).remove(); }); }); </script> <h2>Details</h2> <fieldset> <
<script type="text/javascript">
$(document).ready(function () {
$("#removerow").click(function () {
$(this).remove();
});
});
</script>
<h2>Details</h2>
<fieldset>
<legend>This Question Currently has @Model.Answers.Count() Answers/s. </legend>
<table id="incrementanswer">
<tr>
<th>
Description
</th>
<th>
Answer
</th>
<th></th>
</tr>
@foreach (var answer in Model.Answers.OrderBy(a=> a.IsRight))
{
<tr id = "removerow">
<td>
@Html.DisplayFor(modelItem => answer.Description)
</td>
<td>
@Html.DisplayFor(modelItem => answer.Answer_Description.description)
</td>
<td>
@Ajax.ActionLink("Delete", "Delete", "Answer",
new { id = answer.AnswersID },
new AjaxOptions
{
Confirm = "Are You sure You want to delete this Answer ?",
HttpMethod = "Post",
UpdateTargetId = "toremove",
OnSuccess = "removePartial2"
})
</td>
</tr>
}
</table>
<div id = "progress2">
<img src= "@Url.Content("~/Content/images/ajax-loader1.gif") ">
</div>
$(文档).ready(函数(){
$(“#removerow”)。单击(函数(){
$(this.remove();
});
});
细节
此问题当前有@Model.Answers.Count()个答案/s。
描述
答复
@foreach(Model.Answers.OrderBy(a=>a.IsRight)中的var-answer)
{
@DisplayFor(modeleItem=>answer.Description)
@DisplayFor(modelItem=>answer.answer\u Description.Description)
@ActionLink(“删除”、“删除”、“回答”,
新建{id=answer.AnswersID},
新选择
{
确认=“是否确实要删除此答案?”,
HttpMethod=“Post”,
UpdateTargetId=“toremove”,
OnSuccess=“removePartial2”
})
}
它包含一个脚本和一个ajax.actionlink,在单击删除链接后调用此脚本。当前,仅当该行是表中的第一行时,才会删除该行,并且在确认删除之前,该行也将被删除,因此可能会出现什么问题
已编辑:-我已将视图更新为以下内容,但我仍然无法强制removePartial2脚本删除已删除的行:-
</script>
<script type="text/javascript">
function removePartial2() {
$(this).remove();
}
</script>
}
<h2>Details</h2>
<fieldset>
<legend>This Question Currently has @Model.Answers.Count() Answers/s. </legend>
<table id="incrementanswer">
<tr>
<th>
Description
</th>
<th>
Answer
</th>
<th></th>
</tr>
@foreach (var answer in Model.Answers.OrderBy(a=> a.IsRight))
{
<tr id = @answer.AnswersID>
<td>
@Html.DisplayFor(modelItem => answer.Description)
</td>
<td>
@Html.DisplayFor(modelItem => answer.Answer_Description.description)
</td>
<td>
@Ajax.ActionLink("Delete", "Delete", "Answer",
new { id = answer.AnswersID },
new AjaxOptions
{
Confirm = "Are You sure You want to delete this Answer ?",
HttpMethod = "Post",
UpdateTargetId = @answer.AnswersID.ToString(),
OnSuccess = "removePartial2"
})
</td>
</tr>
}
</table>
<div id = "progress2">
<img src= "@Url.Content("~/Content/images/ajax-loader1.gif") ">
</div>
函数removePartial2(){
$(this.remove();
}
}
细节
此问题当前有@Model.Answers.Count()个答案/s。
描述
答复
@foreach(Model.Answers.OrderBy(a=>a.IsRight)中的var-answer)
{
@DisplayFor(modeleItem=>answer.Description)
@DisplayFor(modelItem=>answer.answer\u Description.Description)
@ActionLink(“删除”、“删除”、“回答”,
新建{id=answer.AnswersID},
新选择
{
确认=“是否确实要删除此答案?”,
HttpMethod=“Post”,
UpdateTargetId=@answer.AnswersID.ToString(),
OnSuccess=“removePartial2”
})
}
@约翰:我已经更新了我的答案。如果ajax调用成功,则删除该行。这意味着服务器返回200个代码。removePartial2中的$(this)是什么?您确定该行引用了您希望它引用的对象吗?我正在尝试强制应用程序删除所需的行,这就是我使用$(this)的原因;但似乎效果不太好。。。。。。