I would like to embed javascript code in razor code. I've tried the following-
<tbody>
@foreach (var row in ViewBag.Retailers.Rows) //Retailers is a datatable
{
<tr>
<td>@row["RegionName"].ToString()</td>
</tr>
<script>
var marker=new Object();
marker.lat=@row["Latitude"].ToString();
marker.lon=@row["Longitude"].ToString();
markersArray.push(marker);
</script>
}
</tbody>
But, it's not working. Any help?
ViewBag.Retailers.Rows?data-*attributes to the table row in the loop, then use one script at the end to build the array and avoid duplicating this script and rendering unnecessary html.