Ajax Toolkit和MVC 2

时间:2010-07-22 11:25:23

标签: asp.net-mvc ajaxcontroltoolkit

我正在使用MVC 2,并尝试将文本框连接到Microsoft AjaxToolkit AutoCompleteBehavior。

我无法触发java脚本。最初我认为我的scrpt引用是错误的,但已将脚本指向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>

1 个答案:

答案 0 :(得分:2)

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

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

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

    <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检查出来。