Ajax 工具包和 MVC 2
我正在尝试使用 MVC 2,并尝试将文本框连接到 Microsoft AjaxToolkit AutoCompleteBehavior。
我无法启动 java 脚本。最初我以为我的脚本引用是错误的,但已将脚本指向 CDN 版本。
看起来我从来没有进入 Sys.Application.add_init(function () { 我创建对象的地方。
有人可以看看我是否遗漏了一些简单的东西。或者我只是做错了?
<script src="http://ajax.microsoft.com/ajax/act/40412/extended/ExtenderBase/BaseScripts.js" type="text/javascript"></script>
<script src="http://ajax.microsoft.com/ajax/act/40412/extended/Common/Common.js" type="text/javascript"></script>
<script src="http://ajax.microsoft.com/ajax/act/40412/extended/Animation/Animations.js" type="text/javascript"></script>
<script src="http://ajax.microsoft.com/ajax/act/40412/extended/Animation/AnimationBehavior.js" type="text/javascript"></script>
<script src="http://ajax.microsoft.com/ajax/act/40412/extended/PopupExtender/PopupBehavior.js" type="text/javascript"></script>
<script src="http://ajax.microsoft.com/ajax/act/40412/extended/Compat/Timer/Timer.js" type="text/javascript"></script>
<script src="http://ajax.microsoft.com/ajax/act/40412/extended/AutoComplete/AutoCompleteBehavior.js" type="text/javascript"></script>
<script type="text/javascript">
Sys.Application.add_init(function () {
$create(Sys.Extended.UI.AutoCompleteBehavior
, { "delimiterCharacters": ""
, "serviceMethod": "ProductNameSearch"
, "servicePath": "/ProductService.asmx"
, "minimumPrefixLength": 1
}
, null
, null
, $get("query"));
});
</script>
<script src="/Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="/Scripts/MicrosoftMVCAjax.js" type="text/javascript"></script>
<%using (Ajax.BeginForm("ProductSearchAC"
, new AjaxOptions { UpdateTargetId = "results" }))
{ %>
<%=Html.TextBox("query",null, new {size=40}) %>
<input type="submit" />
<%} %>
<div id="results">
</div>
I am playing around with MVC 2 a bit and was trying to hook up a text box to the Microsoft AjaxToolkit AutoCompleteBehavior.
and I cannot get the java script to fire. Originally I thought that my scrpt references were wrong but have pointed the scripts to the CDN versions.
it looks like I never enter the Sys.Application.add_init(function () { where I create my object.
could anyone see if I am missing something simple. or am I just doing it wrong?
<script src="http://ajax.microsoft.com/ajax/act/40412/extended/ExtenderBase/BaseScripts.js" type="text/javascript"></script>
<script src="http://ajax.microsoft.com/ajax/act/40412/extended/Common/Common.js" type="text/javascript"></script>
<script src="http://ajax.microsoft.com/ajax/act/40412/extended/Animation/Animations.js" type="text/javascript"></script>
<script src="http://ajax.microsoft.com/ajax/act/40412/extended/Animation/AnimationBehavior.js" type="text/javascript"></script>
<script src="http://ajax.microsoft.com/ajax/act/40412/extended/PopupExtender/PopupBehavior.js" type="text/javascript"></script>
<script src="http://ajax.microsoft.com/ajax/act/40412/extended/Compat/Timer/Timer.js" type="text/javascript"></script>
<script src="http://ajax.microsoft.com/ajax/act/40412/extended/AutoComplete/AutoCompleteBehavior.js" type="text/javascript"></script>
<script type="text/javascript">
Sys.Application.add_init(function () {
$create(Sys.Extended.UI.AutoCompleteBehavior
, { "delimiterCharacters": ""
, "serviceMethod": "ProductNameSearch"
, "servicePath": "/ProductService.asmx"
, "minimumPrefixLength": 1
}
, null
, null
, $get("query"));
});
</script>
<script src="/Scripts/MicrosoftAjax.js" type="text/javascript"></script>
<script src="/Scripts/MicrosoftMVCAjax.js" type="text/javascript"></script>
<%using (Ajax.BeginForm("ProductSearchAC"
, new AjaxOptions { UpdateTargetId = "results" }))
{ %>
<%=Html.TextBox("query",null, new {size=40}) %>
<input type="submit" />
<%} %>
<div id="results">
</div>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来唯一缺少的是在任何 AjaxToolKit 引用之前对 MicrosoftAjax.js 的脚本引用,
我现在已经使用最新的 AjaxToolKit javascript 更新了我的代码,一切正常。万岁!!
感谢 Stephen Walther,他提供了一些关于 AjaxToolkit 和 MVC 的非常好的教程 http://stephenwalther.com/blog/archive/2008/08/24/asp-net-mvc-tip-37-create-an -auto-complete-text-field.aspx 检查它们。
looks like the only thing missing was a script reference to MicrosoftAjax.js before any of the AjaxToolKit references
i have now updated my code with the latest AjaxToolKit javascripts and it all works fine. hooray!!
A Thanks to Stephen Walther who has some very nice tutorials regarding AjaxToolkit and MVC http://stephenwalther.com/blog/archive/2008/08/24/asp-net-mvc-tip-37-create-an-auto-complete-text-field.aspx check them out.