.Net MVC Ajax 和 Scriptmanager 冲突
我们有一个运行良好的简单 ajax 链接 (Ajax.ActionLink(...))。最近,另一位开发人员在使用 asp 脚本管理器的同一页面中添加了一些 ajax-ey 代码...现在突然第一个 ajax 链接不再起作用。更具体地说,我们收到错误:“sys.mvc.asynchyperlink' 为 null 或不是对象”。下面是一个示例:
<a id="linkID"
href="someURL"
onclick="Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace });">
<img src="linkImage.jpg" />
</a>
....
<asp:ScriptManager ID="_someID" EnablePartialRendering="true" ScriptMode="Release" runat="server">
...
</asp:ScriptManager>
这两者之间有什么关系?它们可以共存吗?
编辑: 因此,事实证明我们正在使用 scriptmanager 来注册 ServiceReference 以挂钩到我们已设置的 Web 服务。脚本管理器使我们的 JavaScript 函数可以使用该服务。是否可以在不使用脚本管理器的情况下注册/添加 ServiceReference?这也许是一个完全不同的问题......
We have a simple ajax link (Ajax.ActionLink(...)) that has been working fine. Recently, another developer added some ajax-ey code to the same page that uses an asp scriptmanager ... now suddenly the first ajax link no longer works. More specifically we get the error : "sys.mvc.asynchyperlink' is null or not an object". Below is a sample :
<a id="linkID"
href="someURL"
onclick="Sys.Mvc.AsyncHyperlink.handleClick(this, new Sys.UI.DomEvent(event), { insertionMode: Sys.Mvc.InsertionMode.replace });">
<img src="linkImage.jpg" />
</a>
....
<asp:ScriptManager ID="_someID" EnablePartialRendering="true" ScriptMode="Release" runat="server">
...
</asp:ScriptManager>
What is the relationship between these two? Can they coexist?
EDIT :
so, it turns out we are using the scriptmanager to register a ServiceReference to hook into a web service we've set up. The scriptmanager makes the service available from our javascript functions. Is it possible to get the ServiceReference registered/added without using the scriptmanager? This is perhaps a completely different question...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
ScriptManager 控件不是为与 ASP.NET MVC 共存而构建的。只需将其删除并替换为以下内容即可:
请注意,路径将根据 MicrosoftAjax.js 在项目中的位置而有所不同,但它应该位于任何新 ASP.NET MVC 项目的 Static/js 文件夹中。
The ScriptManager control is not built to coexist with ASP.NET MVC. Just remove it and replace it with the following:
Note that the path will vary based on where MicrosoftAjax.js is in your project, but it should be in the Static/js folder in any new ASP.NET MVC project.
根据记录,我们最终通过使用 Web 服务代理来绕过使用 Scriptmanager 进行服务引用,如 Stephen Walther 在本教程中所述 http://stephenwalther.com/blog/archive/2008/03/14/using-asp- net-ajax-with-asp-net-mvc.aspx
For the record, we ended up getting around using the Scriptmanager for the service reference by using a web service proxy, as outlined in this tutorial by Stephen Walther http://stephenwalther.com/blog/archive/2008/03/14/using-asp-net-ajax-with-asp-net-mvc.aspx