Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

175
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda