title: ASP.net MVC AutoComplete Erroring?
body: <p>I'm trying to get an autocomplete field firing in my asp.net mvc website. Basically the user types in their location and i go out to my db and pre-populate with country and postcodes that match.</p>
  
  <p>The problem im having is that when the view load an error throws saying "Microsoft JScript runtime error: Exception thrown and not caught". It is throwing in the jquery.Ui.widget.js file at the following line:</p>
  
  <pre><code>throw "cannot call methods on " + name + " prior to initialization; " +
                      "attempted to call method '" + options + "'";
  </code></pre>
  
  <p>Following is my script:</p>
  
  <pre><code>&lt;script type="text/javascript" language="javascript"&gt;
  $(function () {
      $.ajaxSetup({ type: "POST" });
      $('#Location').autocomplete('&lt;%= Url.Action("Find") %&gt;', {
          dataType: 'json',
          parse: function (data) {
              var rows = new Array();
              for (var i = 0; i &lt; data.length; i++) {
                  rows[i] = { data: data[i], value: data[i].PlaceName, result: data[i].PlaceName, id: data[i].LocationID };
              }
              return rows;
          },
          formatItem: function (row) {
              return row.PlaceName;
          },
          delay: 300,
          autofill: true,
          selectFirst: true,
          highlight: false
  
      }).result(function (event, row) {
          $("input[id$='LocationID']").val(row.LocationID);
      });
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>I've made sure all the needed jquery files are attached but still cant get it to fire. Ive got the simple default functionality of the autocomplete control to fire (showing a prepopulated list), but as soon as i try to pull from a Json datatype it gives me grief.</p>
  
  <p>Any ideas?</p>