Telerik Kendo UI ASP .NET自动完成示例无法正常工作

时间:2014-11-18 23:35:36

标签: jquery asp.net asp.net-mvc kendo-ui kendo-asp.net-mvc

我只是从这里复制ASP .NET MVC示例: http://demos.telerik.com/aspnet-mvc/autocomplete/index

我的控制器和veiew是完全一样的。但我没有得到自动填充建议。调试控制台抛出以下错误:

Uncaught TypeError: undefined is not a function 
AutoCompleteTest:53(anonymous function) 
AutoCompleteTest:53fire jquery-1.10.2.js:3062
self.fireWith jquery-1.10.2.js:3174
jQuery.extend.ready jquery-1.10.2.js:447
completed

这是导致它的代码行:

jQuery(function(){jQuery("#countries").kendoAutoComplete({"dataSource":["Albania","Andorra","Armenia","Austria","Azerbaijan","Belarus","Belgium","Bosnia \u0026 Herzegovina","Bulgaria","Croatia","Cyprus","Czech Republic","Denmark","Estonia","Finland","France","Georgia","Germany","Greece","Hungary","Iceland","Ireland","Italy","Kosovo","Latvia","Liechtenstein","Lithuania","Luxembourg","Macedonia","Malta","Moldova","Monaco","Montenegro","Netherlands","Norway","Poland","Portugal","Romania","Russia","San Marino","Serbia","Slovakia","Slovenia","Spain","Sweden","Switzerland","Turkey","Ukraine","United Kingdom","Vatican City"],"filter":"startswith","placeholder":"Select country...","separator":", "});});

编辑:_Layout.cshtml的_head标签:

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>@ViewBag.Title - My ASP.NET Application</title>
    @Styles.Render("~/Content/css")
    @Scripts.Render("~/bundles/modernizr")

    <link rel="stylesheet" href="http://cdn.kendostatic.com/2014.2.716/styles/kendo.common-bootstrap.min.css" />
    <link rel="stylesheet" href="http://cdn.kendostatic.com/2014.2.716/styles/kendo.bootstrap.min.css" />

    @Scripts.Render("~/bundles/jquery")

    <script src="http://cdn.kendostatic.com/2014.2.716/js/kendo.all.min.js"></script>
    <script src="http://cdn.kendostatic.com/2014.2.716/js/kendo.aspnetmvc.min.js"></script>

</head>

我用谷歌搜索但无法修复错误。我正在使用jquery 1.10.x. 这是一个简单的例子。我不知道为什么会发生这种情况或如何解决它:(

1 个答案:

答案 0 :(得分:2)

您的代码工作正常。错误是由于jQuery版本的一些兼容性问题。

确保已根据需要包含Kendo所需的所有脚本,即“kendo.all.min.js”和其他脚本。还要确保在包含kendo脚本之前包含jQuery,因为kendo是在jQuery之上构建的。

希望它有所帮助!