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 = [{"No":1,"Name":"Heer"},{"No":1,"Name":"Heer"},{"No":1,"Name":"Heer"}]
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())