title: Ajax jquery autocomplete in ASP.NET MVC 5 C#
body: <p>I know there's a lot of these kind of post but I wasn't able to find any that suited me. I don't have knowledge of ajax and jquery (in fact I've just started with MVC and ASP.NET) so I need your help in this little thing.</p>
  
  <p>There must be almost everywhere this kind of silly thing, I want to write a city name in a combobox, dropdownlist (or whatever) and using a method that I've already created which returns a list of locations (city, country and state names) that match the entered city. I want it to be dinamyc that's why I thought AJAX would solve this (but any other solution is accepted)</p>
  
  <p>I found this <a href="https://github.com/devbridge/jQuery-Autocomplete" rel="nofollow">jQuery autocomplete</a> but I don't understand where to implement it. I want the combobox to match the bootstrap theme. Could someone tell me if this is an appropiate solution and if so where do I put the ajax content and else? (by where I mean, is it in the view, or controller or where?)</p>
  
  <p>Or you could give mi a hint here is the method I've created for getting the elements from the database:</p>
  
  <pre><code>public List&lt;LocationsViewModel&gt; GetHeadquarter(string query)
  {
      var context = new HeadquarterContext();
      //var city = context.Cities.Where(p =&gt; p.Name == query).Single();
      //var province = context.Provinces.Where(p =&gt; p.ProvinceID == city.Province).ToList();
      //foreach(Province prov in province) {
  
      //}
      var hq =
          from c in context.Cities
          join p in context.Provinces on c.Province equals p.ProvinceID
          join co in context.Countries on p.Country equals co.CountryID
          where c.Name == query
          select new { country = co.Name, province = p.Name, city = c.Name };
  
      List&lt;LocationsViewModel&gt; listLocation = new List&lt;LocationsViewModel&gt;();
  
      foreach (var hqe in hq)
      {
          LocationsViewModel loc = new LocationsViewModel();
          loc.City = hqe.city;
          loc.Country = hqe.country;
          loc.Province = hqe.province;
          listLocation.Add(loc);
      }
      return listLocation;
  }
  </code></pre>