Today I had a problem of adding markers onto a google map. I didn't really want to create a service to handle the request and return an array. So instead I tried doing something simpler.
1 2 3 |
@foreach(var pins in Model.Pins) { {latLog: [@Html.DisplayFor(item => pins.Lat), @Html.DisplayFor(item => pins.Log)], data: '@Html.DisplayFor(item => pin.Name'}, } |
This obviously didn't work. Razor was getting confused; it didn't know which one was the script and which one was the text. The solution to this problem is actually very simple: <text>
tag. It allow razer to distinguish between the script and razor.
1 2 3 4 5 6 7 |
@foreach (var pin in Model.Pins) { <text> { latLng: [@Html.DisplayFor(item => pin.Latitude), @Html.DisplayFor(item => pin.Longitude)], data: "@Html.DisplayFor(item => pin.Name)" }, </text> } |