Despite Razor's limitation of generating HTML, the
<script type="text/javascript"> // Some JavaScript code here to display map, etc. // Now add markers @foreach (var item in Model) { <text> var markerlatLng = new google.maps.LatLng(@(Model.Latitude), @(Model.Longitude)); // ... JavaScript code to add markers </text> } </script>
An alternative to
<script type="text/javascript"> // Declare addMarker function function addMarker(latitude, longitude, title, description, map) { // ... JavaScript code } // Now add markers @foreach (var item in Model) {
The above is the detailed content of How Can I Embed Razor Syntax within JavaScript in ASP.NET MVC Views?. For more information, please follow other related articles on the PHP Chinese website!