Send array from view to controller as class – ASP.NET Core.


To send array values from table in view to controller as array class I’ll use JQuery and Ajax. For the needs of the example I generate table in view.

table jquery

Then I create array in javascript and push all value from table to this array. The name in the array should be the same as the names in the class that will be the parametr in the controller.

And model class:

Next we use ajax to send the array to controller.

And our controller look like this.It is important to add [FromBody] if we use ASP.NET Core.

send values from view to controller

By using these methods we can easily send large amounts of data in one class without creating controllers with a high number of parametrs.

Link to project.

Leave a Reply

Your email address will not be published. Required fields are marked *