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')"
它工作正常。我也尝试过:
OnSuccess="function() { VendorCreated(); }"
但出现运行时错误。其他人也遇到这个问题,但我没有找到解决方案,请参阅 MVC 3 Razor - Ajax。 BeginForm OnSuccess 和 Ajax.BeginForm OnBegin 通过 jquery 确认模态。
如果我查看 IE 调试器 (F12),我在生成的代码中没有看到脚本标记...正确的方法是什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,我已经缩小了问题范围...上面的代码是由一个视图生成的,该视图通过 jQuery 加载到另一个视图中的 DIV 中。我最近发现我可以使用 @Html.Action() 在另一个视图中包含一个视图,这样做似乎可以解决上述问题。我现在收到回电!
对于任何有兴趣的人来说,解释为什么其中一种有效而另一种无效将是很好的。
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.
您的页面中是否包含
jquery.unobtrusive.ajax.js
?Are you including
jquery.unobtrusive.ajax.js
in your page?