title: jquery ui autocomplete Uncaught TypeError: Cannot read property '0' of undefined
body: <p>I have this error as displayed in the console:</p>
  <blockquote>
  <pre><code>jquery-3.3.1.js:7972 Uncaught TypeError: Cannot read property '0' of undefined
  
  at val (jquery-3.3.1.js:7972)
  at add (jquery-3.3.1.js:8463)
  at buildParams (jquery-3.3.1.js:8450)
  at Function.jQuery.param (jquery-3.3.1.js:8483)
  at Function.ajax (jquery-3.3.1.js:9073)
  at $.&lt;computed&gt;.&lt;computed&gt;.source (Index:189353)
  at $.&lt;computed&gt;.&lt;computed&gt;._search (VM12 jquery-ui-1.12.1.js:6015)
  at $.&lt;computed&gt;.&lt;computed&gt;._search (VM12 jquery-ui-1.12.1.js:144)
  at $.&lt;computed&gt;.&lt;computed&gt;.search (VM12 jquery-ui-1.12.1.js:6007)
  at $.&lt;computed&gt;.&lt;computed&gt;.search (VM12 jquery-ui-1.12.1.js:144)
  </code></pre>
  </blockquote>
  <p>and it is sent when I start typing.</p>
  <p>my script is</p>
  <pre><code>$('#pesticideTypeInput').autocomplete({
      source: function (request, response) {
          $.ajax({
              url: '@Url.Action(&quot;GetPesticideTypesList&quot;, &quot;Search&quot;)',
              dataType: &quot;json&quot;,
              data: { search: $('#pesticideTypeInput').val },
              success: function (data) {
                  response($.map(data, function (item) {
                      //return { label: item.PesticideTypeAR, value: item.PesticideTypeAR };
                      return item;
                  }));
              },
              error: function (xhr, status, error) {
                  alert(&quot;Error&quot;);
              }
          });
      }
  });
  </code></pre>
  <p>in my controller I have:</p>
  <pre><code>public JsonResult GetPesticideTypesList(string term)
  {
      var pesticidesTypesList = db.PesticideTypes.Where(x =&gt; x.PesticideTypeAR.Contains(term)).ToList();
      return new JsonResult {Data=pesticidesTypesList, JsonRequestBehavior=JsonRequestBehavior.AllowGet };
  }
  </code></pre>
  <p>My model class is:</p>
  <pre><code>public partial class PesticideType
  {
      public PesticideType()
      {
          this.PesticidesInfoes = new HashSet&lt;PesticidesInfo&gt;();
      }
  
      public int PesticideTypePk { get; set; }
      public string PesticideTypeAR { get; set; }
      
      public virtual ICollection&lt;PesticidesInfo&gt; PesticidesInfoes { get; set; }
  }
  </code></pre>
  <p>I appreciate any help, thanks!</p>