Ale*_*lex 5 javascript ajax asp.net-mvc
我有一个@ Ajax.ActionLink,只有在满足某些条件(用户有未保存的更改)时才会显示确认对话框.我创建了一个javascript函数,根据需要显示确认对话框,并根据响应返回true或false.我将它绑定到ActionLink的onclick事件,但是错误的结果不会取消操作.这是我的代码示例:
@Ajax.ActionLink("Done", .. , .. ,
new AjaxOptions() { UpdateTargetId = "MyContainerId"},
new { onclick = "ConfirmDone()" })
Run Code Online (Sandbox Code Playgroud)
这是javascript函数
function ConfirmDone() {
//for testing purposes we can always show the dialog box
return confirm("Are you sure you want to lose unsaved changes?");
}
Run Code Online (Sandbox Code Playgroud)
显示Ajax.ActionLink的条件确认对话框的最佳方法是什么?
Dis*_*ile 14
使用OnBegin事件:
@Ajax.ActionLink("Done", "ActionName",
new AjaxOptions
{
OnBegin = "return ConfirmDone()",
UpdateTargetId = "MyContainerId"
})
Run Code Online (Sandbox Code Playgroud)
如果您只需要弹出一个确认框,也可以使用Confirm ajax选项.如果您需要执行更多自定义逻辑(或想要使用自定义对话框),则需要使用OnBegin.
以下是使用确认的示例:
@Ajax.ActionLink("Done", "ActionName",
new AjaxOptions
{
Confirm= "Are you sure you want to do this?",
UpdateTargetId = "MyContainerId"
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10061 次 |
| 最近记录: |