Rogerio Azevedo Rogerio Azevedo - 1 year ago 80
JSON Question

Send two lists by Json and Get it from Array on JavaScript

I have two lists on my controller and I send that lists as ARRAY in a json to JavaScript.

See my Controller code here:

var aval = new List<AvaliacaoViewModel>();
aval = relData.GetAvaliacao(data_1, data_2, cliente, operador);

var resumo = new List<ResumoViewModel>();
resumo = relData.GetResumo(data_1, data_2, cliente, operador);

var result = new { aval = aval, resumo = resumo };
return Json(result, JsonRequestBehavior.AllowGet);

My list1 - Controller-1

My list2 - COntroller-2

Its working fine and I can see two ARRAYS on JavaScript:

url: '/Relatorios/AvalOperador',
dataType: "json",
type: "GET",
data: { 'data1': data1, 'data2': data2, 'operador': operador },
success: function (data) {


var aval1 = avalia.getValue(1);
var aval2 = avalia.getValue(2);
var aval3 = avalia.getValue(3);
var aval4 = avalia.getValue(4);

Now I need...

Get data from list1 (controller1) and put it on 4 strings, like:

var avalia1 = column[1].toString();
var avalia1 = column[2].toString();
var avalia1 = column[3].toString();
var avalia1 = column[4].toString();

And the Second List/Array pass it to a HTML Table

<table class="table table-striped">
<th>Pie </th>

<td>Patrick Smith</td>
<td><span class="pie">85/100</span></td>

Console Stringfy:


Answer Source

Based on the trincot's comment, I found the solution with a friend's help.

            url: '/Relatorios/AvalOperador',
            dataType: "json",
            type: "GET",
            data: { 'data1': data1, 'data2': data2, 'operador': operador },
            success: function (data) {

                var aval1 = JSON.stringify(data.aval[0].Avalia1);
                var aval2 = JSON.stringify(data.aval[0].Avalia2);
                var aval3 = JSON.stringify(data.aval[0].Avalia3);
                var aval4 = JSON.stringify(data.aval[0].Avalia4);

                var resumo = "";

                for (var i in data.resumo) {
                    resumo += "<tr>" +
                        "<td>" + data.resumo[i].Cod + "</td>" +
                        "<td>" + data.resumo[i].Qtde + "</td>" +
                        "<td>" + data.resumo[i].Result + "</td>" +