rysahara
rysahara

Reputation: 356

Data format for generating table with json mvc ASP.NET

I'm doing some queries in the database and must return through the Json, but I can not hit the fomato. I'm doing the following:

var dataResult = new List<List<Object>>();

I query the database and and add below

dataResult.Add(new List<object>(new object[] { "rRod:" + rod, "rKmI:" + vlrkmI, "rKmF:" + vlrkmF, "rExt:" + ext, "rSol:" + sol }));

To assemble the table use

function (data) {
    $("#divResult").empty();

    //Adicionar a tabela na div
    table = "<fieldset style='height:50px '><legend>Resultado da Matriz</legend><table id='tableResult'><tr><th>Rod</th>";
    table += "<th>kmI</th><th>kmF</th><th>Ext</th><th>Sol</th></fieldset>"
    $("#divResult").append(table);

    $(eval(data)).each(function (data) {
    $("#tableResult").append(
        "<tr><td>" + this.rRod+ "</td>" + 
        "<td>" + this.rKmI + "</td>" + 
        "<td>" + this.rKmF + "</td>"
        "<td>" + this.rExt + "</td>" +
        "<td>" + this.rSol + "</td></tr>");
});

But not this genrando the table with values​​.

Upvotes: 0

Views: 271

Answers (1)

qamar
qamar

Reputation: 1447

What I would suggest you to do is instead of doing a list of object create a class with those properties something like this :

var dataResult = new List<List<sometypewhichhasallofthosejsobproperties>>();

Now from the mvc action just simply return jsonresult of the dataresult. This should format your data to json nicely and you should be able to work with it in jquery easily.

Upvotes: 1

Related Questions