Click here to Skip to main content
15,888,733 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
<pre>
--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
:::
CSS
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.
Posted

1 solution

I think your LIBRARY is not loading properly. Please use Resolve url to load your library.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900