asp.net mvc 3 - How to handle a string with apostrophe in DotNet.highcharts -


i have code:

categories = new[]  { "jan", "feb", "mar", "apr", "may", "jun", "jul",    "aug", "sep", "oct", "nov", "dec" }; 

this works nicely dotnet.highcharts in mvc3. however, trying dynamically populate categories result querying northwind database such

ienumerable <string> fname = u in db.order_details.take(12)                              join w in db.products                              on u.productid equals w.productid                              select w.productname;  string[] namearr = (string[])fname.toarray();  .....  .setxaxis(new xaxis {     categories = namearr  .... 

now of namarr have apostrophes in them , highcharts cannot handle those.

how solve issue?

woah!!! found solution after digging through internet. , answering own question might find useful , save loads if time. apparently there 2 approaches

string[] namearr = (string[])fname.toarray(); int j = 0; foreach (string name in namearr) {     // option 1     // namearr[j++]= httputility.htmlencode(name);      // option 2     namearr[j++] = name.replace("'", "\\\'"); } 

the commented solution leaves html encoded, second 1 works fine.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -