I'm currently working with asp.net mvc2 and attempting to send a list of JSON objects with predefined values from the home controller, then receive them in the index page.... the code snippet below shows how I am sending a single JSON object .... but how can I send multiple objects at once?
Here is the code in the home controller:
public ActionResult JsonValue()
{
var result = new
{
pID = 1,
pName = "Lina",
pStart = "",
pEnd = "",
pColor = "ff0000",
pLink = "",
pMile = 0,
pRes = "Brian",
pComp = 0,
pGroup = 1,
pParent = 0,
pOpen = 1
};
return Json(result,JsonRequestBehavior.AllowGet);
And here is how you would receive it in the index page:
var Jid = null;
var Jname = null;
var Jstart = null;
var Jend = null;
var Jcolor = null;
var Jlink = null;
var Jmile = null;
var Jres = null;
var Jcomp = null;
var Jgroup = null;
var Jparent = null;
var Jopen = null;
var Jtitle = null;
var g = new JSGantt.GanttChart('g', document.getElementById('GanttChartDIV'), 'day');
$(document).ready(function () {
$.getJSON('../../Home/JsonValue', function (data) {
Jid = data.pID;
Jname = data.pName;
Jstart = data.pStart;
Jend = data.pEnd;
Jcolor = data.pColor;
Jlink = data.pLink;
Jmile = data.pMile;
Jres = data.pRes;
Jcomp = data.pComp;
Jgroup = data.pGroup;
Jparent = data.pParent;
Jopen = data.pOpen;
Jtitle = '|id= ' + Jid + '|Name: ' + Jname + '|Start: ' + Jstart + '|End: ' + Jend;
}); // end $.getJSON
Thank you very much for any help you can provide! -Lina