自动完成对象或属性未定义 [英] Autocomplete Object or property not defined
本文介绍了自动完成对象或属性未定义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<pre>
- 我正在尝试以下程序。但我在jquery中遇到错误。请帮助我。
---控制器
--I am trying the below program. But I am getting error in jquery. Kindly help me.
---controller
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using autocomplete.Models;
namespace autocomplete.Controllers
{
public class HomeController : Controller
{
public ActionResult Index2()
{
return View();
}
public JsonResult Employeename(string name)
{
Employee Emp = new Employee();
List<Employee> EmployeeList = new List<Employee>();
EmployeeList.Add(new Employee { EmployeeNames = "Anurag", EmployeeId = 11 });
EmployeeList.Add(new Employee { EmployeeNames = "Abhi", EmployeeId = 12 });
EmployeeList.Add(new Employee { EmployeeNames = "Anupama", EmployeeId = 13 });
EmployeeList.Add(new Employee { EmployeeNames = "Abhishek", EmployeeId = 114 });
EmployeeList.Add(new Employee { EmployeeNames = "Anirudh", EmployeeId = 23 });
EmployeeList.Add(new Employee { EmployeeNames = "Bibek", EmployeeId = 234 });
var a = EmployeeList.Where(x=>x.EmployeeNames.StartsWith(name)).Select(x=>x.EmployeeNames).ToList();
return Json(a, JsonRequestBehavior.AllowGet);
}
}
}
----查看
----view
@model IEnumerable<autocomplete.Models.Employee>
<link href="~/Content/jquery-ui-1.10.4.custom.min.css" rel="stylesheet" />
<script src="~/Scripts/jquery-1.10.2.js"></script>
<script src="~/Scripts/jquery-ui-1.10.4.custom.min.js"></script>
<script type="text/javascript">
$(document).ready(function ()
{
$("#txtsearch").autocomplete ({
source: '@Url.Action("Employeename")'
});
});
</script>
<h2>Index1</h2>
<div style="font-family:Arial">
@using (@Html.BeginForm())
{
Name
@Html.TextBox("SearchTerm", null, new { Id="txtsearch"})
}
我收到错误
:::
I am getting error
:::
Unhandled exception at line 50, column 9 in http://localhost:62008/Home/Index2
0x800a01b6 - Microsoft JScript runtime error: Object doesn't support property or method 'autocomplete'
::
----Kindly guide me where I am doing wrong.
推荐答案
(document).ready(function()
{
(document).ready(function () {
(#txtsearch)。autocomplete({
source:'@ Url.Action(Employeename)'
});
});
< / script>
< h2> Index1< / h2>
< div style =font-family:Arial>
@using(@ Html.BeginForm())
{
名称
@ Html.TextBox(SearchTerm ,null,new {Id =txtsearch})
}
("#txtsearch").autocomplete ({ source: '@Url.Action("Employeename")' }); }); </script> <h2>Index1</h2> <div style="font-family:Arial"> @using (@Html.BeginForm()) { Name @Html.TextBox("SearchTerm", null, new { Id="txtsearch"}) }
我收到错误
:::
I am getting error
:::
Unhandled exception at line 50, column 9 in http://localhost:62008/Home/Index2
0x800a01b6 - Microsoft JScript runtime error: Object doesn't support property or method 'autocomplete'
::
----Kindly guide me where I am doing wrong.
我认为你的LIBRARY没有正确加载。请使用Resolve url加载您的库。
I think your LIBRARY is not loading properly. Please use Resolve url to load your library.
这篇关于自动完成对象或属性未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文