1

I have a model list of data to map chart. But the map chart accepts value format like this:

data: [{id: 'London', lat: 51.50, lon: -0.12}]

But the below code produce a data like this

enter image description here

The Id value is in double quote what I need is single quote 'London' and it should not display like that '&quot'. The sample chart with data can be found here https://jsfiddle.net/gh/get/library/pure/highcharts/highcharts/tree/master/samples/maps/demo/flight-routes/

Model

[JsonObject(MemberSerialization.OptIn)]
    public class ShipmentLocationModel
    {
        [JsonProperty]
        public string id { get; set; }
        [JsonProperty]
        public decimal lat { get; set; }
        [JsonProperty]
        public decimal lon { get; set; }
    }

Controller

List<ShipmentLocationModel> LocationList = new List<ShipmentLocationModel>();
var stringWriter = new StringWriter();
var serializer = new JsonSerializer();
using (var writer = new JsonTextWriter(stringWriter))
{
    writer.QuoteName = false;
    serializer.Serialize(writer, LocationList);
}
ViewData["LocationList"] = stringWriter;

View

data: @ViewData["LocationList"]

Reynan
  • 163
  • 1
  • 1
  • 11

1 Answers1

0

Use @Html.Raw() method:

data: @Html.Raw(ViewData["LocationList"])
JMSilla
  • 1,326
  • 10
  • 17
  • Hi the output was still double quote but it is not '&quot' anymore data: [{id: "London", lat: 51.50, lon: -0.12}] – Reynan Jul 31 '19 at 07:44
  • sorry it works now that is weird single or double quote works now. thank you. – Reynan Jul 31 '19 at 07:50