c# - Send color hex from controller to view without quotes becomes "? -
i struggling send through value , color pair json, color value has returned javascript in view color: "#ffffff"
example, , can send view that, second browser reads it becomes color: "#ffffff"
doesn't work. snippet of code:
values.add(new studentbrandsapp.models.statsvalues() { value = convert.toint32(dr.itemarray[1].tostring()), color = "#f38630" }); // populate values. var serializer = new jsonserializer(); var stringwriter = new stringwriter(); var writer = new jsontextwriter(stringwriter); writer.quotename = false; serializer.serialize(writer, values); writer.close(); var json = stringwriter.tostring(); json = httputility.htmlencode(json); viewdata["json"] = json;
and in javascript:
<script src="~/scripts/chart.js"></script> <script type="text/javascript"> @{string jsonstring = viewdata["json"].tostring();} var data = @jsonstring; //get context of canvas element want select var ctx = document.getelementbyid("mychart").getcontext("2d"); var mynewchart = new chart(ctx).pie(data); //get context jquery - using jquery's .get() method. var ctx = $("#mychart").get(0).getcontext("2d"); //this first returned node in jquery collection. var mynewchart = new chart(ctx); new chart(ctx).pie(data, options); </script>
here chart.js documentation on how values , colors should represented pie charts: http://www.chartjs.org/docs/
you need write @html.raw(jsonstring)
prevent razor automatically escaping it.
Comments
Post a Comment