title: Autocomplete on Html.TextBox won't work
body: <p>So, I've searched alot and went through alot of tutorials and even though I do everything exactly as in the tutorial, I just can't seem to get it working. Funny thing is, I have been involved in a project where we used the exact same solution and it worked.</p>
  
  <p>I've got a textbox in my forum where users can search for threads in all categories where I am using ajax to show the result in a div in form of a partial view. This is working. </p>
  
  <p><strong>The problem is</strong> that I want the thread subjects that are containing the current search term to show up (in form of a normal string) while the user is typing, but I can't seem to get the implementation of autocomplete right. By the way I am retrieving my information from a MSSQL-database.</p>
  
  <p>This is the javascript that I am using to autocomplete (which is not working) and below that you can see my Ajax-form that I use for the search (that works):</p>
  
  <pre><code>&lt;link href="~/Content/jquery-ui.min.css" rel="stylesheet" /&gt;
  &lt;script src="~/Scripts/jquery-ui.min.js"&gt;&lt;/script&gt;
  
  @*Scripts for  Ajax to show the partial view in the div with id "partialThreads" at request*@
  &lt;script src="~/Scripts/jquery-2.2.1.min.js"&gt;&lt;/script&gt;
  &lt;script src="~/Scripts/jquery.unobtrusive-ajax.min.js"&gt;&lt;/script&gt;
  
  
  
  &lt;script type="text/javascript"&gt;
      $(function () {
  
          $("#txtSearch").autocomplete({
              source: '@Url.Action("GetThreadsBySearch", "Forum")'
          });
      });
  
  &lt;/script&gt;
  
  
  @using (@Ajax.BeginForm("Threads", new AjaxOptions() { UpdateTargetId = "partialThreads", InsertionMode = InsertionMode.Replace, HttpMethod = "POST" }))
  {
      @Html.AntiForgeryToken()
      &lt;p&gt;&lt;strong&gt;Search for thread in all categories&lt;/strong&gt;&lt;/p&gt;
      @Html.TextBox("searchTerm", null, new { id = "txtSearch", style = "width: 1000px" })
      &lt;input type="submit" value="Search" /&gt;
  }
  </code></pre>
  
  <p>Here is the div where I show the results of the search in form of a partial view:</p>
  
  <pre><code>&lt;div id="partialThreads"&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p>Here is the action method that I am using for my ajax-form search (the working one):</p>
  
  <pre><code>    [HttpPost, ValidateAntiForgeryToken]
      public ActionResult Threads(string searchTerm)
      {
          var model = string.IsNullOrWhiteSpace(searchTerm)
              ? new List&lt;ThreadsListModel&gt;()
              : _threadRepo.GetThreadsBySearch(searchTerm).OrderByDescending(x =&gt; x.DateCreated).ToList();
  
          return PartialView("_Threads", model);
      }
  </code></pre>
  
  <p>And here is the method that I use to retrieve the information to my autocomplete (I've tried setting a break point on it, it doesn't even break):</p>
  
  <pre><code>    public JsonResult GetThreadsBySearch(string term)
      {
          var threadNames = _threadRepo.GetThreadsBySearch(term).Select(x =&gt; x.Subject).ToList();
          return Json(threadNames, JsonRequestBehavior.AllowGet);
      } 
  </code></pre>
  
  <p>Note that I use the same db-query to search with the form and for the autocomplete (only difference would be that I select the threadnames as a List in the <strong>GetThreadsBySearch</strong> method. So that can't be the problem (?). Here is query-method in case you want to have a look:</p>
  
  <pre><code>    public ICollection&lt;ThreadsListModel&gt; GetThreadsBySearch(string subject)
      {
          using (var context = new ForumContext())
          {
              return
                  context.Threads.Where(x =&gt; x.Subject.ToLower().Contains(subject.ToLower()) &amp;&amp; x.IsActive)
                      .Select(x =&gt; new ThreadsListModel()
                      {
                          ID = x.ID,
                          DateCreated = x.DateCreated,
                          CreatedBy = x.CreatedBy,
                          Subject = x.Subject,
                          PostsCount = x.Posts.Count
                      }).Distinct().ToList();
          }
      }
  </code></pre>
  
  <p>Also, I am using Visual Studio 2015 (.NET 4.5.2) MVC 5. I hope that I haven't forgot to write down any helpful information. </p>