JavaScriptSerializer with Razor and ASPX engine

I am serializing a list object using the JavaScriptSerializer and assigning the result to a javascript object but when i use the aspx engine the quotes in the json string are considered as double quotes and working correct but when using razor engine the double quotes are printed as " and through exception.

How to resolve this?

My sample code.

ASPX:

var data = <%=JsonConverter.ConvertDataTabletoString()%>
var data = [{"No":"1","Name":"John"},{"No":"2","Name":"Smith"},  {"No":"3","Name":"Tomps"},{"No":"4","Name":"Hanar"},{"No":"5","Name":"Reek"}]`

Razor:

var data = @JsonConverter.ConvertDataTabletoString()
var data = [{&quot;No&quot;:1,&quot;Name&quot;:&quot;Heer&quot;},{&quot;No&quot;:1,&quot;Name&quot;:&quot;Heer&quot;},{&quot;No&quot;:1,&quot;Name&quot;:&quot;Heer&quot;}]

Answers


Try using Html.Raw() to print out the code in the Razor view. That will stop the code from being HTML-escaped.

Eg:

@Html.Raw(JsonConverter.ConvertDataTabletoString())

Need Your Help

Shiny's tabsetPanel not displaying plots in multiple tabs

r tabs plot shiny

I am trying to use multiple tabPanel controls within the tabsetPanel in Shiny. Lets say I start with only one tab using the following code:

How to initiate zoomability in a Sunburst with selection from dropdown

javascript jquery d3.js

I have a sunburst for which I would like to initiate zoom ability via dropdown. That is when a country name is selected from the drop down menu its part in the sunburst zooms exactly like when its