Ajax.BeginForm上的回调不起作用 [英] Callbacks on Ajax.BeginForm don't work

查看:290
本文介绍了Ajax.BeginForm上的回调不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法获取表单的回调。我有这样的:

 < script> 
function VendorCreated(){
alert('ok');
}
< / script>

@using(Ajax.BeginForm(Create,Vendor,new AjaxOptions {
UpdateTargetId = ViewBag.TargetId,
HttpMethod =Post,
OnSuccess =VendorCreated,
})){

。如果我使用:

  OnSuccess =alert('ok')
/ pre>

它工作正常。我也试过:

  OnSuccess =function(){VendorCreated();}

但我得到一个运行时错误。其他人遇到这个问题,但我没有找到解决方法,请参阅 MVC 3 Razor - Ajax。 BeginForm OnSuccess Ajax.BeginForm OnBegin确认通过jquery modal



如果我看看IE调试器(F12),我在代码生成中没有看到脚本标记...什么是正确的方法?

解决方案

确定,我把问题缩小了...上面的代码是由一个视图生成的,一个DIV在另一个视图中通过jQuery。我最近发现,我可以包括一个视图在另一个视图使用@ Html.Action(),这样似乎解决了上面的问题。我现在得到回调!



对于有倾向的任何人,解释为什么一个工作,而不是另一个是伟大的。


I'm having difficulty getting the callbacks to work for a form. I have something like this:

<script>
function VendorCreated() {
  alert('ok');
}
</script>

@using (Ajax.BeginForm("Create", "Vendor", new AjaxOptions {
    UpdateTargetId = ViewBag.TargetId, 
    HttpMethod = "Post", 
    OnSuccess="VendorCreated",
    })) {

upon submission my function never gets created. If I use:

OnSuccess="alert('ok')"

it works fine. I've also tried:

OnSuccess="function() { VendorCreated(); }"

but I get a runtime error. Others are having this issue but I've found no resolution, see MVC 3 Razor - Ajax.BeginForm OnSuccess and Ajax.BeginForm OnBegin confirmation Via jquery modal.

If I look at the IE debugger (F12) I don't see a script tag in the code generated... what's the right approach?

解决方案

ok, I've narrowed the problem down... the code above is generated by a view which gets loaded into a DIV in another view by jQuery. I've recently discovered that I can include a view within another view using @Html.Action() and doing so seems to resolve the problem above. I now get callbacks!

for anyone with the inclination, an explanation of why one works and not the other would be great.

这篇关于Ajax.BeginForm上的回调不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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