对于以下内容:
@Ajax.ActionLink("Delete", "Delete", "AdminGroup", new { id = item.AdminGroupId }, new AjaxOptions { Confirm = "Delete?", HttpMethod = "Delete", OnSuccess = "function() { $(this).parent().parent().remove() }" })
Run Code Online (Sandbox Code Playgroud)
OnSuccess得到了错误.请帮忙.谢谢
Dar*_*rov 23
它应该是这样的:
@Ajax.ActionLink(
"Delete",
"Delete",
"AdminGroup",
new { id = item.AdminGroupId },
new AjaxOptions {
Confirm = "Delete?",
HttpMethod = "Delete",
OnSuccess = "handleSuccess"
}
)
Run Code Online (Sandbox Code Playgroud)
你在哪里:
<script type="text/javascript">
function handleSuccess() {
// TODO: handle the success
// be careful because $(this) won't be
// what you think it is in this callback.
}
</script>
Run Code Online (Sandbox Code Playgroud)
这是我建议你的替代解决方案:
@Html.ActionLink(
"Delete",
"Delete",
"AdminGroup",
new { id = item.AdminGroupId },
new { id = "delete" }
)
Run Code Online (Sandbox Code Playgroud)
然后在单独的javascript文件中AJAXify链接:
$(function() {
$('#delete').click(function() {
if (confirm('Delete?')) {
var $link = $(this);
$.ajax({
url: this.href,
type: 'DELETE',
success: function(result) {
$link.parent().parent().remove();
}
});
}
return false;
});
});
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
19799 次 |
最近记录: |