title: Get information from database with ajax ASP.NET
body: <p>I'm trying to get some information from a table in my database whenever a <code>select</code>-field changes.</p>
  
  <p>I'm able to do the response and the Ajax jQuery function return success(function)<br>
  The problem is i don't know how to return the data from my database using ASP.net MVC.<br>
  The response i'm getting from my Ajax call on success is this text:</p>
  
  <pre><code>ProduktWebKort.Models.WarehouseCustomer[]
  </code></pre>
  
  <p>This is the part of my controller with the function called via Ajax</p>
  
  <pre><code>[HttpPost]
  public string OnChange(int id)
  {
      return db.Customers.Where(C =&gt; C.CustomerID == id).ToString();
  }
  </code></pre>
  
  <p>My Ajax call looks like this:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  $(function () {
      // Document.ready -&gt; link up remove event handler
      $("#CustomerID").change(function () {
          alert("Hej");
          var option = $('option:selected', this).val();
          $.ajax({
              type: "POST",
              url: '@Url.Action("Index/1", "Session")',
              contentType: "application/json; charset=utf-8",
              data: { id: 1 },
              dataType: "html",
              success: function (success) {
                  alert('Success');
                  console.log(success);
                  for (var i = 0; i &lt; success.length; i++) {
                      $(".form-horizontal").append("&lt;li&gt;" + success[i] + "      &lt;/li&gt;");
                      console.log(success);
                  }
              },
              error: function (e, text, string) {
                  alert(e.message + text + string);
                  console.log(e);
              }
          });
      });
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>I want to return every entry from <code>WarehouseCustomer</code> with the <code>CustomerID</code> of id from my select field.</p>