title: Autocomplete Textbox in C# and MVC
body: <p>Hi to all and thanks for your help,</p>
  
  <p>I need to autocomplete a textbox with suggestions in C# and MVC.</p>
  
  <p>The textbox in the view is:</p>
  
  <pre><code>&lt;div class="col-lg-3 col-md-3 hidden-sm hidden-xs" style="margin-top:2%;"&gt;
     &lt;input type="text" class="formLocator" value="Milano" data-date-end-date="0d" id="textLocator" name="searchstring"&gt;
     &lt;h4 class="FormTextLocator"&gt;Where&lt;/h4&gt;
  &lt;/div&gt;
  &lt;div class="hidden-lg hidden-md col-sm-3 col-xs-12" style="margin-top:2%;"&gt;
     &lt;input type="text" class="formLocator" value="Milano" data-date-end-date="0d" id="textLocator" name="searchstring"&gt;
     &lt;h4 class="FormTextLocator"&gt;Where&lt;/h4&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I have created a javascript code for this textbox:</p>
  
  <pre><code>$(function () 
  {
      $("#textLocator").autocomplete(
      {
          source: "/Home/AutocompleteSuggestions",
          minLength: 1,
          select: function (event, ui) 
          {
              if (ui.item) 
              {
                  $("#textLocator").val(ui.item.value);
                  $("form").submit();
              }
          }
      });
  });
  </code></pre>
  
  <p>And the controller associated is: </p>
  
  <pre><code> public JsonResult AutocompleteSuggestions(string searchstring)
   {
       var db = new TocFruit();
       var suggestions = from s in db.city select s.name;
       var namelist = suggestions.Where(n =&gt; n.ToString().StartsWith(searchstring.ToLower()));
       return Json(namelist, JsonRequestBehavior.AllowGet);
   }
  </code></pre>
  
  <p>But all of this doesn't work but i don't understand what I'm doing wrong.</p>
  
  <p>Thanks to all,</p>
  
  <p>Roberto</p>