Ajax 工具包和 MVC 2

发布于 2024-09-11 02:59:17 字数 2040 浏览 3 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

往日情怀 2024-09-18 02:59:17

看起来唯一缺少的是在任何 AjaxToolKit 引用之前对 MicrosoftAjax.js 的脚本引用,

 <script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>

我现在已经使用最新的 AjaxToolKit javascript 更新了我的代码,一切正常。万岁!!

    <script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>
    <script src="../../Scripts/MicrosoftAjaxToolkit/ExtenderBase/BaseScripts.js" type="text/javascript"></script>    
    <script src="../../Scripts/MicrosoftAjaxToolkit/Common/Common.js" type="text/javascript"></script>    
    <script src="../../Scripts/MicrosoftAjaxToolkit/Animation/Animations.js" type="text/javascript"></script>
    <script src="../../Scripts/MicrosoftAjaxToolkit/PopupExtender/PopupBehavior.js" type="text/javascript"></script>
    <script src="../../Scripts/MicrosoftAjaxToolkit/Animation/AnimationBehavior.js" type="text/javascript"></script>
    <script src="../../Scripts/MicrosoftAjaxToolkit/Compat/Timer/Timer.js" type="text/javascript"></script>    
    <script src="../../Scripts/MicrosoftAjaxToolkit/AutoComplete/AutoCompleteBehavior.js" type="text/javascript"></script>

感谢 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

 <script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>

i have now updated my code with the latest AjaxToolKit javascripts and it all works fine. hooray!!

    <script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>
    <script src="../../Scripts/MicrosoftAjaxToolkit/ExtenderBase/BaseScripts.js" type="text/javascript"></script>    
    <script src="../../Scripts/MicrosoftAjaxToolkit/Common/Common.js" type="text/javascript"></script>    
    <script src="../../Scripts/MicrosoftAjaxToolkit/Animation/Animations.js" type="text/javascript"></script>
    <script src="../../Scripts/MicrosoftAjaxToolkit/PopupExtender/PopupBehavior.js" type="text/javascript"></script>
    <script src="../../Scripts/MicrosoftAjaxToolkit/Animation/AnimationBehavior.js" type="text/javascript"></script>
    <script src="../../Scripts/MicrosoftAjaxToolkit/Compat/Timer/Timer.js" type="text/javascript"></script>    
    <script src="../../Scripts/MicrosoftAjaxToolkit/AutoComplete/AutoCompleteBehavior.js" type="text/javascript"></script>

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文