在确认对话框上单击“是”或“否”后,不会触发 OnSuccessForm() 函数。关于如何在继续之前停止 onBeginForm() 的任何想法?
我的 MVC3 表单
@using (Ajax.BeginForm("Edit", @ViewContext.Controller.ValueProvider.GetValue("controller").RawValue, new AjaxOptions
{
UpdateTargetId = Model.Title.Replace(" ", "") + "Form",
InsertionMode = InsertionMode.Replace,
OnBegin = "onBeginForm",
OnSuccess = "OnSuccessForm",
OnFailure = "showFaliure"
}))
{
@Html.ValidationSummary(true)
@Html.RenderStandardEditor("Edit " + Model.Title)
}
这是我的 JavaScript 示例代码
<script type="text/javascript">
var confirmation = false;
function onBeginForm(ajaxContext)
{
$.confirm({
'title': 'Confirmation',
'message': 'Confirm?',
'buttons': {
'Yes': {
'class': 'cyan',
'action': function ()
{
confirmation = true;
}
},
'No': {
'class': 'gray',
'action': function ()
{
confirmation = false;
}
}
}
});
}
function OnSuccessForm(ajaxContext)
{
if (confirmation == true)
{
//DO SOMETHING
}
}
function showFaliure(ajaxContext)
{
//THROW ERROR
}
</script>