Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

169
Vistas
Unable to Send List Of Array via ajax to Controller

I have list of array Generated from dynamically created textbox values .The Issue Is while passing data to controller using ajax ,the count of list is showing in jsonresult but unable to get the list.Its showing Like [object,Object],[object,Object] like the image I added. What I want to retrieve data from list.

My Data Binding Code

     $('#tbl tbody tr').each(function () {
        var objlist = [];
       
        var count = 0;
        var row = $(this).closest('tr');
        var rowIndex = $(this).closest('tr').index();
        row.find('input[type=text]').each(function () {
           
            count += 1;
                var id    = $(this).attr('id');
                var value = $(this).val();
                var field = $(this).attr('name');
                objlist.push({
                    "Id": id,
                    "field": field,
                    "value": value
                });
                });
       
        tblList.push(objlist);
        });

My Ajax Sending Method

        $.ajax({
        type: 'POST',
        url: '@Url.Action("Action", "Controller")',
        data:  {tableData: tblList},
        global: false,
        dataType: "json",
        traditional: true,
        async: false,
        success: function (data) {
          ///
            }
        }
    });

The List Of arrays
data After Sending to controller

Modified Data

After Modification Its Showing this Thank you.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

This code was tested using Visual Studio and working properly

Ajax should use application/json content type

$.ajax({
        type: 'POST',
        url: '@Url.Action("Action", "Controller")',
        data: JSON.stringify(tblList),
        contentType: 'application/json; charset=utf-8',
        dataType: 'json',
        success: function (data) {
          ///
            }
        }
    });

on server side create a viewmodel

public class TableData
{
public int Id {get; set;}
public string Field {get; set;}
public string Value{get; set;}
}

and change action header too

public JsonResult InsertData([FromBody]List<TableData> tableData)

and I think it is a bug in your code you have array inside of another array. You have to fix it before using code

      objlist.push({
                    "Id": id,
                    "field": field,
                    "value": value
                });
                });
       
        tblList.push(objlist);

if you need 2 arrays try this action

public JsonResult InsertData([FromBody] List<List<TableData>> tableData)
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda