Problem passing a record size from Ajax to Controller in Asp net core 5 mvc

PEDRO FERNANDO OSTAIZA GARCIA 26 Reputation points
2022-02-17T14:42:52.27+00:00

Hello friends, I have a problem when passing information from Ajax to the controller, for example I am passing 126 records and if it arrives to the controller, but if I add one more product it arrives null, I am using asp net core 5, I would appreciate your help.

In this two first image if the information comes to me well
175464-c1.png175472-c2.png

When an item is added more I get null
175445-c3.png175446-c4.png

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,525 questions
0 comments No comments
{count} vote

Accepted answer
  1. Zhi Lv - MSFT 32,156 Reputation points Microsoft Vendor
    2022-02-18T07:39:11.977+00:00

    Hi @PEDRO FERNANDO OSTAIZA GARCIA ,

    Can you directly share the relates code (such as the JS scripts, the Ventas and DetallesViewModel), instead of using the image? If you can't directly post them, you can create a txt file and share it via the attachment. Then, we can based on your code to reproduce the problem and help you fix the problem.

    Besides, I also create a sample on my side and use JQuery Ajax to transfer lots of data to the action method, it works well. So, the issue might not relate the count. You can check this screenshot:

    175708-1.gif

    You can view the source code from here: 176700-sourcecode.txt


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    Best regards,
    Dillion


1 additional answer

Sort by: Most helpful
  1. Michael Taylor 53,896 Reputation points
    2022-02-17T16:39:15.97+00:00

    There isn't an array size limit in MVC (but there is a request size limit). However your model looks incorrect to me. This is a post so I assume you're passing your data in the body of the request. In the body of the request you would normally have a single model, not multiple. Hence I would expect your controller to accept a single model and within that model you'd have child properties for ventas and detaile.

    public class MyModel
    {
       public VentasViewModel Ventas { get; set; }
       public List<DetailesViewModel> Detailes { get; set; }
    }
    
    [HttpPost]
    public IActionResult Guardarventas ( MyModel model )
    {
    }
    

    Also look at the actual body that was sent in the request and make sure the JSON lines up when you get to the 127th item.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.