Ajax.ActionLink AjaxOptions 回调问题 (ASP.NET MVC 3)
我在 PartialView
中有一个 Ajax.ActionLink
,如下所示:
@Ajax.ActionLink(Model.IsVisible ? "Disable" : "Enable", "ToggleVisibility", "Review", new { area = "Admin", id = Model.Id }, new AjaxOptions { HttpMethod = "POST", OnComplete = "onComplete_AdminReviewOption" })
处理 JavaScript 函数(目前在主视图上内嵌声明):
function onComplete_AdminReviewOption(ajaxContext) {
var jsonObject = ajaxContext.get_object();
}
抛出一个 javascript 错误:
Object# 没有 get_object() 的定义
。
我认为这些 JavaScript 方法是 MicrosoftAjax.js
/ MicrosoftMvcAjax.js
脚本的一部分,这两个脚本我都包含在我的页面上。
任何人都可以确认这些辅助方法存在哪个库吗?
我在 Layout.cshtml
文件中加载所需的脚本,然后执行 AJAX 调用来渲染上面的 PartialView。
因此,当我处理该函数时,库已经加载 - 这就是我感到困惑的原因。
有什么想法吗?
I have an Ajax.ActionLink
inside a PartialView
like so:
@Ajax.ActionLink(Model.IsVisible ? "Disable" : "Enable", "ToggleVisibility", "Review", new { area = "Admin", id = Model.Id }, new AjaxOptions { HttpMethod = "POST", OnComplete = "onComplete_AdminReviewOption" })
And the handling JavaScript function (declared in-line on the main View for now):
function onComplete_AdminReviewOption(ajaxContext) {
var jsonObject = ajaxContext.get_object();
}
Which throws a javascript error:
Object# has not definition for get_object()
.
I thought these JavaScript methods were part of the MicrosoftAjax.js
/ MicrosoftMvcAjax.js
scripts, both of which i have included on my page.
Can anyone confirm which library these helper methods are present?
I load the required scripts in my Layout.cshtml
file, then i do an AJAX call to render out the above PartialView.
So by the time i handle that function, the libraries are already loaded - which is why im confused.
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您似乎正在使用 ASP.NET MVC 3 和 Razor。在此版本中,jQuery 是默认的客户端脚本框架。不再有
MicrosoftAjax.js
(感谢上帝)。所以:也不要忘记包含
jquery.unobtrusive-ajax.js
。如果您想使用旧的东西,您可以通过在 web.config 中设置以下内容:
默认情况下,此变量设置为 true。
就我个人而言,我更喜欢使用标准链接:
并在单独的 javascript 文件中使用 jQuery 对它们进行 AJAXify:
It looks like you are using ASP.NET MVC 3 and Razor. In this version jQuery is the default client scripting framework. No more
MicrosoftAjax.js
(thanks God). So:Also don't forget to include
jquery.unobtrusive-ajax.js
.If you want to use the legacy stuff you could by setting the following in your web.config:
By default this variable is set to true.
Personally I prefer to use standard links:
and AJAXify them using jQuery in a separate javascript file: