title: C# MVC5 Jquery auto complete, fail to return JSON Data
body: <p>I am a beginner in programming, I have researched a few places to implement the jquery <code>autocomplete</code>. I managed to call postback to <code>JSON GROUP method</code>. But after success, I can't manage to get the <code>JSON results</code> or if I code it wrongly. Please help</p>
  
  <p><strong>Code</strong></p>
  
  <pre><code>$(function () {
      $("#txtGRP_CODE").autocomplete({
          source: function (request, response) {
              $.ajax({
                  url: '/AutoComplete/GRP_CODE',
                  dataType: "json",
                  type: "POST",
                  contentType: "application/json; charset=utf-8",
                  data: "{ 'prefix': '" + request.term + "'}",
                  success: function (data) {
                      response($.map(data, function (item) {
                          return { label: item.Name, value: item.Name };
                      }))
                  },
                  error: function (response) {
                      alert(response.responseText);
                  },
                  failure: function (response) {
                      alert(response.responseText);
                  }
              });
          },
          select: function (e, i) {
              $("#txtGRP_CODE").val(i.item.value);
          },
          minLength: 1
      });
  });
  </code></pre>
  
  <p><strong>Server Side</strong></p>
  
  <pre><code>[HttpPost]
  public JsonResult GRP_CODE(string prefix)
      {
          List&lt;AutoCompleteController&gt; listGroup = new List&lt;AutoCompleteController&gt;();
  
          string sSQL = " SELECT * FROM icgrp WHERE GRP_CODE like '" + prefix + "%'";
          DataTable dt = conn2.GetData(sSQL);
          using (MySqlDataReader dr = conn2.ExecuteReader(sSQL))
          {
              //foreach (DataRow dr in ds.Tables[0].Rows)
              while (dr.Read())
              {
                  listGroup.Add
                  (new search
                      {
                          Name = dr["GRP_CODE"].ToString(),
                          Sr_no = dr["GRP_PART"].ToString()
                      }
                  );
              }
          }
  
         //**I manage to populate listGroup but when passing it to the client side I can't get the Json data. 
  
          return Json(listGroup, JsonRequestBehavior.AllowGet);
      }
  </code></pre>
  
  <p><strong>Server Side</strong></p>
  
  <p><a href="https://ibb.co/sVbKSYG" rel="nofollow noreferrer">https://ibb.co/sVbKSYG</a></p>
  
  <p><strong>Client side</strong></p>
  
  <p><a href="https://ibb.co/09CFXdW" rel="nofollow noreferrer">https://ibb.co/09CFXdW</a></p>
  
  <p><strong>Network Client Response</strong></p>
  
  <p><a href="https://ibb.co/BB61dRd" rel="nofollow noreferrer">https://ibb.co/BB61dRd</a></p>
  
  <p><strong>Response</strong></p>
  
  <pre><code>Server Error in '/' Application.
  The resource cannot be found.
  Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable.  Please review the following URL and make sure that it is spelled correctly. 
  
   Requested URL: /AutoComplete/GRP_CODE
  
   Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.3282.0
  </code></pre>