title: ASP.NET Core MVC Ajax not working properly
body: <p>My issue is very very simple but I have not found any solution about this issue in the entire internet. I am new at ASP.NET CORE MVC and I feel its AJAXs is very hard to understand compared to the normal ASP.NET.</p>
  <p>Well I am trying to pass an array/list of objects to controller but I cant make this. It is Very simple but it does not work the way I want ( In the normal ASP.NET MVC worked great).</p>
  <p>For example I have this:</p>
  <pre><code>var detalleVenta = new Array();
  
       $.each($(&quot;#tableventa tbody tr&quot;), function () {
  
                   detalleVenta.push( 
                       {
                           &quot;ProductoId&quot; :  $(this).find(&quot;td&quot;).eq(6).html(),
                           &quot;Cantidad&quot; :  $(this).find(&quot;td&quot;).eq(2).html(),
                           &quot;Precio&quot; :  $(this).find(&quot;td&quot;).eq(3).html(),
                           &quot;Total&quot; :  $(this).find(&quot;td&quot;).eq(4).html() 
                       }
                       ); 
              });
  
          $.ajax({
            method:&quot;POST&quot;,
            data: JSON.stringify(detalleVenta),
            &quot;dataType&quot;: &quot;json&quot;,
            &quot;contentType&quot;: &quot;application/json&quot;,
             url: '@Url.Action(&quot;GuardarVenta&quot;, &quot;Venta&quot;)',
             traditional: true,         
             success: function(data, textStatus) { 
             if (data == &quot;OK&quot; ){
             location.href = '@Url.Action(&quot;Index&quot;,&quot;Compra&quot;)'          
          }
      }
          ,
          })
  </code></pre>
  <p>MVC controller:</p>
  <pre><code>public JsonResult GuardarVenta([FromBody]List&lt;DetalleBinding&gt; detalle)
  {
        ...
  }
  
  public class DetalleBinding
  {
      public string ProductoId {get; set;}
      public string Cantidad {get;set;}
      public string Precio {get;set;}
      public string Total {get;set;}
  }
  </code></pre>
  <p>This way worked for me, ajax sends the list successfully data to controller:</p>
  <p><a href="https://i.stack.imgur.com/oQ6dw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/oQ6dw.png" alt="enter image description here" /></a></p>
  <p>But my issue is... what if I want to send more data appart from that data? I Normally write it in JSON format like this : <code>data : { &quot;detalle&quot; : detalleVenta, &quot;Name&quot; : &quot;Mary&quot;, &quot;Age&quot; : 34}</code> but my issue is that this does not work for me.</p>
  <p>I tried this:</p>
  <pre><code> $.ajax({
      method:&quot;POST&quot;,
      data: {&quot;detalle&quot; : JSON.stringify(detalleVenta)},
      &quot;dataType&quot;: &quot;json&quot;,
      &quot;contentType&quot;: &quot;application/json&quot;,
      url: '@Url.Action(&quot;GuardarVenta&quot;, &quot;Venta&quot;)',
      traditional: true,         
      success: function(data, textStatus) { 
      if (data == &quot;OK&quot; ){
          location.href = '@Url.Action(&quot;Index&quot;,&quot;Compra&quot;)'          
          }
      }
          ,
          })
  </code></pre>
  <p>But it does not bind to controller and gives me null.</p>
  <p><a href="https://i.stack.imgur.com/flIpL.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/flIpL.png" alt="enter image description here" /></a></p>
  <p>What I am doing wrong?</p>
  <p>This is what <code>console.log(JSON.stringify(detalleVenta))</code> shows:</p>
  <p><a href="https://i.stack.imgur.com/S8K3P.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/S8K3P.png" alt="enter image description here" /></a></p>