title: How to Implement Autocomplete Textbox in MVC
body: <p>I am facing a problem in autocompleting the textbox vith hardcoded data, my json "Search" method does not fire i have been search a lot of code implement it into my project but did not get any success yet. i dont know where is the problem. kindly help me thankx in advance </p>
  
  <blockquote>
    <p>Model:</p>
  </blockquote>
  
  <pre><code>  public class Locations
      {
  
          public int Id { get; set; }
          public string Name { get; set; }
  
      }
  </code></pre>
  
  <blockquote>
    <p>Controller:</p>
  </blockquote>
  
  <pre><code>public JsonResult Search(string query)
          {
              List&lt;Locations&gt; locations = new List&lt;Locations&gt;()
          {
              new Locations() {Id = 1, Name = "London"},
              new Locations() {Id = 2, Name = "Walles"},
              new Locations() {Id = 3, Name = "Birmingham"},
              new Locations() {Id = 4, Name = "Edinburgh"},
              new Locations() {Id = 5, Name = "Glasgow"},
              new Locations() {Id = 6, Name = "Liverpool"},
              new Locations() {Id = 7, Name = "Bristol"},
              new Locations() {Id = 8, Name = "Manchester"},
              new Locations() {Id = 9, Name = "NewCastle"},
              new Locations() {Id = 10, Name = "Leeds"},
              new Locations() {Id = 11, Name = "Sheffield"},
              new Locations() {Id = 12, Name = "Nottingham"},
              new Locations() {Id = 13, Name = "Cardif"},
              new Locations() {Id = 14, Name = "Cambridge"},
              new Locations() {Id = 15, Name = "Bradford"},
              new Locations() {Id = 16, Name = "Kingston Upon Hall"},
              new Locations() {Id = 17, Name = "Norwich"},
              new Locations() {Id = 18, Name = "Conventory"}
  
              };
              List&lt;string&gt; Loc;
              Loc = locations.Where(x =&gt; x.Name.StartsWith(query.ToLower())).Select(x =&gt; x.Name).ToList();
              return Json(Loc, JsonRequestBehavior.AllowGet);
          }
  </code></pre>
  
  <blockquote>
    <p>View:</p>
  </blockquote>
  
  <pre><code>@model IEnumerable&lt;SearchBox.Models.Locations&gt;
  @using SearchBox.Models
  @{
      ViewBag.Title = "Index";
  }
  
  &lt;link href="~/Content/Autocomplete/jquery-ui.css" rel="stylesheet" /&gt;
  &lt;script src="~/Content/Autocomplete/jquery-ui.js"&gt;&lt;/script&gt;
  &lt;link href="~/Content/Autocomplete/jquery-ui.theme.css" rel="stylesheet" /&gt;
  
  &lt;script type="text/javascript"&gt;
      $("#tags").autocomplete({
          source: '@Url.Action("Search")'
      });
  &lt;/script&gt;
  
      &lt;input type="text" id="tags" /&gt;
  </code></pre>