websss
asked on
Float array in c# - when passed to JS it's in wrong order
Hi, I have the float array which is populated in c#
I then prepare the data in c# to be send to the front end by doing the following (this might be where its going wrong)
then in the front end i have
However the value in position 321,228 in JS is not the same as in C#, so i assume its re-ordered the data some how
Can anyone advise where its getting muddled up?
I've attached the dataset which is was taken on a BP on this line
ViewBag.TempDataArray = pd.TemperatureDataArray
The correct value in the float array at this position [321, 228] should be 346.795624
However in the front end i'm seeing 304.92453
temperatureData= new float[570, 429];
I then prepare the data in c# to be send to the front end by doing the following (this might be where its going wrong)
System.Web.Script.Serialization.JavaScriptSerializer jSearializer = new System.Web.Script.Serialization.JavaScriptSerializer();
jSearializer.MaxJsonLength = int.MaxValue;
pd.TemperatureDataArray = jSearializer.Serialize(temperatureData);
ViewBag.TempDataArray = pd.TemperatureDataArray;
then in the front end i have
var tempDataArray = @(ViewBag.TempDataArray);
var imageTemperatureDataArray = JSON.stringify(tempDataArray);
imageTemperatureDataArray = JSON.parse(imageTemperatureDataArray);
alert(imageTemperatureDataArray[321, 228]);
However the value in position 321,228 in JS is not the same as in C#, so i assume its re-ordered the data some how
Can anyone advise where its getting muddled up?
I've attached the dataset which is was taken on a BP on this line
ViewBag.TempDataArray = pd.TemperatureDataArray
The correct value in the float array at this position [321, 228] should be 346.795624
However in the front end i'm seeing 304.92453
Have you check your indices? Not that you're off by one..
ASKER
Yes, I did check the surrounding values, it's not the issue
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks
I implemented what you said
On this line i get UNDEFINED
the console.write output is in the attached file
consolewrite.txt
I implemented what you said
On this line i get UNDEFINED
alert(imageTemperatureDataArray[321][228]);
the console.write output is in the attached file
consolewrite.txt
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks all
Kelvin, this was the bit that got it working
@Html.Raw(ViewBag.TempData Array);
Kelvin, this was the bit that got it working
@Html.Raw(ViewBag.TempData
ASKER
Hey guys, sorry for bringing this up again, but I have a slightly different issue
I've also accessed this float array from a ajax url.action Post
In the CS i return an object in JSONResult
However its a javascript variable at this point and cannot run @Html.Raw(ViewBag.TempData Array);
its coming back as
[[273.7,273.8,273.8,274.6, 274.4 etc
And I need to convert it to array as this did: @Html.Raw(ViewBag.TempData Array);
Any ideas?
I've also accessed this float array from a ajax url.action Post
In the CS i return an object in JSONResult
However its a javascript variable at this point and cannot run @Html.Raw(ViewBag.TempData
its coming back as
[[273.7,273.8,273.8,274.6,
And I need to convert it to array as this did: @Html.Raw(ViewBag.TempData
Any ideas?
ASKER
you can comment here
https://www.experts-exchange.com/questions/29143994/html-raw-in-jquery.html
https://www.experts-exchange.com/questions/29143994/html-raw-in-jquery.html
I commented there, requesting your Controller method code.