我有一个Ajax.ActionLink
向服务器发送请求并从服务器获取结果。所以在AjaxOption
中我只写了成功函数的名称。
OnSuccess = "SuccessDeleteFunction"
但基于结果我想改变DOM元素。为了在成功函数中传递当前DOM元素,我使用了这段代码:
OnSuccess = "SuccessDeleteFunction(this)"
但我怎样才能同时拥有两者。
function SuccessDeleteFunction(result, tag) {
if (result.Success) {
// do sth
}
eval(result.Script);
}
这是我的代码:
@foreach (var item in Model)
{
<tr class="ContentRow">
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Email)
</td>
<td>
@Ajax.ActionLink(" ", "Delete", "Product", new { id = @item.Id }, new AjaxOptions() { Confirm = "Are you sure?", HttpMethod = "get", OnSuccess = "SuccessDeleteFunction" }, new { @class = "btn fa fa-trash text-danger fa-2x " })
</td>
</tr>
}
答案 0 :(得分:0)
您必须将项目ID
改为TR:
@foreach (var item in Model)
{
<tr class="ContentRow" id="tr_'@item.id'">
<td>
@Html.DisplayFor(modelItem => item.Name)
</td>
<td>
@Html.DisplayFor(modelItem => item.Email)
</td>
<td>
@Ajax.ActionLink(" ", "Delete", "Product", new { id = @item.Id }, new AjaxOptions() { Confirm = "Are you sure?", HttpMethod = "get", OnSuccess = "SuccessDeleteFunction" }, new { @class = "btn fa fa-trash text-danger fa-2x " })
</td>
</tr>
}
在您的JS
代码中,您必须执行此操作,而您需要更多的内容是从ID
SERVER RESPONSE
function SuccessDeleteFunction(result) {
if (result.Success) {
// also return your that id from server in response....
$("tr_" + result.id).remove();
}
eval(result.Script);
}