触发OnSuccessForm前Ajax.BeginForm确认对话框onBeginForm()()对话框、Ajax、OnSuccessForm、onBeginForm

由网友(他葬爱我葬忆)分享简介:在我已经在确认对话框中单击OnSuccessForm无论是是或否()函数不会触发。继续之前就如何制止onBeginForm任何想法()?我的MVC3表格@using(Ajax.BeginForm(编辑,@ ViewContext.Controller.ValueProvider.GetValue(控制器)。RawVal...

在我已经在确认对话框中单击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>
 
ajax表单搜索

解决方案

我相信你使用的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?

阅读全文

相关推荐

最新文章