I have ASP.Net MVC3 application. And My task is to read points from file and display them. For reading points from file I use DLL. I draw them in javascript. Here is my code:
// Controller
{
IntPtr lib = LoadLibrary("lib.dll");
// getting points from DLL. I get then as array of strings to serialise later
string[] points = new string[0];
GetArrayPointsAsStrings(points); // I get coordinates - [x1, y1, z1, x2, y2, z2, ..]
FreeLibrary(lib);
JavaScriptSerializer serializer = new JavaScriptSerializer();
serializer.MaxJsonLength = Int32.MaxValue;
string serialized_points = serializer.Serialize(points);
return View(new MyModel(serialized_points));
}
// Model
public class MyModel
{
public string Points { get; private set; }
}
// View
@{
var m = Model;
var array_of_strings_points = m.Points;
}
// object from javascript
var js_obj = new js_obj();
var points_string = '@Html.Raw(@array_of_strings_points)';
js_obj.DrawPoints(points_string);
//js
//.. and here in DrawPoints() I parse the string of points and draw point
My question is: Is it ok to pass all serialized points to string from controller to javascript this way? May be there is better way to pass all points to javascript?
Thanks, Zhenya