0

I have the following AJAX call to a controller action method:

$.ajax({
  type: "POST",
  url: "/BasesDados/Produtos/EditarProduto",
  data: { 
    objProduto: objProduto, 
    listProdutoLinguas: produtoLinguas, 
    listCoresTamanhos: corTamanhos, 
    atributoIDs: attIDs 
  },
  success: function (res) {
    // ..do something
  }
});

I am populating the objects within the script before calling the AJAX function. It works fine and sends the data to the controller, unless it has a big chunk of data to be sent. In a specific error case, the object 'corTamanhos' is populated with 261 elements (it's an array of objects), and in this particular case, the AJAX call fails, it never sends the request over to the server.

I've tried so many things like, JSON.serialize, using a formData element, I'm getting desperate.

After checking the console, I discovered the error is an Exception, as follows:

"InvalidDataException: Form value count limit 1024 exceeded."

How can I overcome this?

Anyone can help?

Thank you very much in advance.

Lelio Faieta
  • 6,457
  • 7
  • 40
  • 74
  • 2
    When you say 'it fails' and 'it never sends the request to the server' have you checked the console for any errors? Also check the network tab of the console after making the request to see if it is actually sent but the server rejects it. Then you can debug the issue from there. – Rory McCrossan Feb 05 '20 at 10:03
  • Well, I know it never gets to the server because I am running in debug mode, and have multiple breakpoints in the Action Method, and it never gets called. For other cases with a bit less data, it runs perfectly. – Paulo Assunção Feb 05 '20 at 10:11
  • That doesn't mean the request isn't made. That means your code isn't hit. It's entirely possible that the request is sent correctly, but the server is rejecting it for any number of reasons, eg. request size too large, invalid data/format for the model binder to work with, authorization issues. This is why you need to debug the actual response you're getting. – Rory McCrossan Feb 05 '20 at 10:17
  • Yes you're right. In the meanwhile, I discovered the error is an exception: InvalidDataException: Form value count limit 1024 exceeded. Updated the original post. – Paulo Assunção Feb 05 '20 at 10:18
  • In that case [try this](https://stackoverflow.com/q/38357108/519413) – Rory McCrossan Feb 05 '20 at 10:26
  • Thank you for your guidance. I've managed to solve it by changing the limit in the startup class, like explained in one answer to the post you suggested!! Thank you very much!! – Paulo Assunção Feb 05 '20 at 10:29
  • No problem, glad it helped – Rory McCrossan Feb 05 '20 at 10:29

1 Answers1

0

Thanks to @Rory McCrossan guidance in the comments, I was able to find the problem and solve it.

The exception was throwing because the default size limit for a form submit is 1024.

I was able to set it in the Startup class, like explained in this post: https://stackoverflow.com/a/50077801/8796120

Thnak you!!