触发OnSuccessForm前Ajax.BeginForm确认对话框onBeginForm()() [英] Ajax.BeginForm Confirmation Dialog onBeginForm() before triggering OnSuccessForm()

查看:372
本文介绍了触发OnSuccessForm前Ajax.BeginForm确认对话框onBeginForm()()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我已经在确认对话框中单击OnSuccessForm无论是是或否()函数不会触发。继续之前就如何制止onBeginForm任何想法()?

我的MVC3表格

  @using(Ajax.BeginForm(编辑,@ ViewContext.Controller.ValueProvider.GetValue(控制器)。RawValue,新AjaxOptions
{
  UpdateTargetId = Model.Title.Replace(,)+形,
  InsertionMode = InsertionMode.Replace,
  OnBegin =onBeginForm
  的onSuccess =OnSuccessForm
  OnFailure =showFaliure
}))
{
  @ Html.ValidationSummary(真)
  @ Html.RenderStandardEditor(编辑+ Model.Title)
}
 

下面是我的JavaScript样本code

 <脚本类型=文/ JavaScript的>
  VAR确认= FALSE;
  功能onBeginForm(ajaxContext)
  {
    $ .confirm({
    '标题':'确认',
    信息:确认?,
    按钮:{
      '是': {
        类:青色,
        行动:函数()
        {
          确认=真;
        }
      },
      '没有': {
        类:灰色,
        行动:函数()
        {
          确认= FALSE;
        }
      }
    }
  });
}

功能OnSuccessForm(ajaxContext)
{
  如果(确认==真)
  {
    //做一点事
  }
}

功能showFaliure(ajaxContext)
{
  //抛出一个异常
}

< / SCRIPT>
 

解决方案

我相信你使用的onSuccess函数不正确。该函数将被调用只有在您的数据发布成功。所以,无论什么选择在您的确认框数据将得到张贴无论哪种方式,然后将您的确认框中只有确定anythings做与此数据它发布之后。这是真的,你想要什么?

至于为什么你onSuccessForm不被打,我能提供的是方法来尝试调试它。是showFaliure获取调用呢?用Firebug控制台的数据得到公布呢?如果您注释掉一切你onBeginForm函数内部onSuccessForm获取调用呢?

After I have clicked either 'Yes' or 'No' on the confirmation dialog the OnSuccessForm() function does not trigger. Any ideas on how to halt the onBeginForm() before continuing?

My MVC3 Form

@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)
}

Here is my JavaScript Sample Code

<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>

解决方案

I believe you're using the onSuccess function incorrectly. That function will get called only after your data is posted successfully. So regardless of what's chosen in your confirmation box data will get posted either way, and then your confirmation box only determines if anythings done with this data after it's posted. Is this truly what you want?

As for why your onSuccessForm isn't being hit, all I can offer is ways to try debugging it. Is showFaliure getting called instead? Using the firebug console is data getting posted at all? If you comment out everything inside your onBeginForm function is onSuccessForm getting called then?

这篇关于触发OnSuccessForm前Ajax.BeginForm确认对话框onBeginForm()()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆