jquery - Pass Json Data To MVC Razor View -



jquery - Pass Json Data To MVC Razor View -

i'm using jquery flot charts http://www.flotcharts.org/ within mvc 5 application. wish create horizontal bar charts, , tutorial helpful http://www.jqueryflottutorial.com/how-to-make-jquery-flot-horizontal-bar-chart.html

the next 3 lines of code pass in info chart plugin uses create chart

var rawdata = [[1582.3, 0], [28.95, 1], [1603, 2], [774, 3], [1245, 4], [85, 5], [1025, 6]]; var dataset = [{ label: "precious metal price", data: rawdata, color: "#e8e800" }]; var ticks = [[0, "gold"], [1, "silver"], [2, "platinum"], [3, "palldium"], [4, "rhodium"], [5, "ruthenium"], [6, "iridium"]];

my charts however, can not utilize hard coded values above, , instead info passed chart needs dynamic. can pass info rowdata variable using ajax phone call in mvc razor view calls controller action returns json (see below).

$.ajax({ type: "get", contenttype: 'application/json; charset=utf-8', datatype: 'json', url: '/statistics/gettestdata/', error: function () { alert("an error occurred."); }, success: function (data) { var rawdata = [data]; } });

my problem how can pass info controller action ticks variable?

i suppose need know is, can homecoming controller action 2 sets of data, 1 rawdata variable in format of

[[1582.3, 0], [28.95, 1], [1603, 2], [774, 3], [1245, 4], [85, 5], [1025, 6]]

and, secondly ticks variable in format of

[[0, "gold"], [1, "silver"], [2, "platinum"], [3, "palldium"], [4, "rhodium"], [5, "ruthenium"], [6, "iridium"]]

hopefully makes sense.

any feedback or advice appreciated.

thanks.

can homecoming controller action 2 sets of data

of course, composite model. action returns 1 thing, thing can model has more 1 property on it. don't know object structure, contrived model might like:

public class chartviewmodel { public rawdatamodel rawdata { get; set; } public ticksmodel ticks { get; set; } }

then controller action homecoming instance of that:

var model = new chartviewmodel { rawdata = getrawdata(), ticks = getticks() }; homecoming json(model);

this composite model becomes convenient place include other properties or behavior might needed other client-side code or other views related one.

then in client-side code set values based on properties:

success: function (data) { var rawdata = data.rawdata; var ticks = data.ticks; // etc. }

jquery ajax asp.net-mvc json flot

Comments

Popular posts from this blog

javascript - THREE.js reposition vertices for RingGeometry -

javascript - I need to update the text of a paragraph by inline edit -

assembly - What is the addressing mode for ld, add, and rjmp instructions? -