Don't try to build a JSON string manually. Instead, build a collection of objects, and then use a proper JSON serializer to generate the JSON.
Model:
public class Marker
{
public string title { get; set; }
public double lat { get; set; }
public double lng { get; set; }
public string description { get; set; }
}
Action:
public ActionResult GoogleMaps()
{
var markers = new List<Marker>();
string conString = ConfigurationManager.ConnectionStrings["eNtsaRegistration"].ConnectionString;
using (var con = new SqlConnection(conString))
using (var cmd = new SqlCommand("SELECT Name, Latitude, Longitude, Description FROM dbo.Locations", con))
{
con.Open();
using (var sdr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
{
while (sdr.Read())
{
markers.Add(new Marker
{
title = Convert.ToString(sdr["Name"]),
lat = Convert.ToDouble(sdr["Latitude"]),
lng = Convert.ToDouble(sdr["Longitude"]),
description = Convert.ToString(sdr["Description"]),
});
}
}
}
ViewBag.Markers = markers;
return View();
}
View:
<script>
var markers = @Html.Raw(Json.Encode(ViewBag.Markers));