title: ASP.NET MVC 4 jQuery autocomplete problems
body: <p>I am new to MVC and trying to get autocomplete working on a textbox to return suggested MemberNames. I have two problems (Problem1 - getting the user's initial text characters into the controller, and Problem2 - getting returned controller list of names to appear below the text box).</p>
  
  <p>View: </p>
  
  <pre><code>@section scripts{ 
      &lt;script type="text/javascript"&gt;
          $(document).ready(function () {
              $("#autocomplete").autocomplete({ source: '@Url.Action("MemberList", "Grievances", new { autocomplete = $("#autocomplete").val() })' });
      });     
      &lt;/script&gt;
  }
  ...
  &lt;input id="autocomplete"&gt;
  </code></pre>
  
  <p>Problem1 - In the above View, if I do not put in the 3rd parameter for @Url.Action, my controller receives null for parameter value (even though a bunch of websites tell me autocomplete automatically binds this value, it's not doing it). </p>
  
  <p>If I put in a hardcode for the 3rd parameter, like this:</p>
  
  <pre><code>new { autocomplete = "ead" }
  </code></pre>
  
  <p>then the controller receives "ead" as parameter value. If I put in the code as it is in the code block above, the website errors out, complaining of "Unexpected character '$'" in the 3rd parameter.</p>
  
  <p>Question1 - How can I pass the value of the autocomplete text box into the controller?</p>
  
  <p>Problem2 - Here is my controller code</p>
  
  <pre><code>public ActionResult MemberList(string autocomplete)
  {
  var memberNames = (from p in context.Members
                     where p.MemberName.Contains(autocomplete)
                     select p.MemberName).Distinct().Take(10);
  string content = string.Join&lt;string&gt;("\n", memberNames);
  return Content(content);
  }
  </code></pre>
  
  <p>When I hard code a value (like 'ead') into the 3rd parameter in the view above, then I get the value here in the controller. The Controller retrieves a list of appropriate records from the database, and I return it back to the View. However, nothing shows up under the text box. I do have the necessary JavaScript and CSS files included in the View; if I hard code a list of values, they do show up appropriately under the text box. It's only the controller that it can't get the results from.</p>
  
  <p>Question2 - How do I get the controller to return a list of values so the autocomplete text box will show them?</p>
  
  <p>Your help with these 2 problems is greatly appreciated. I feel like I'm just spinning my wheels in the mud getting autocomplete to work.</p>