title: Using Razor within JavaScript
body: <p>Is it possible or is there a workaround to use Razor syntax within JavaScript that is in a view (<code>cshtml</code>)?</p>
  
  <p>I am trying to add markers to a Google map... For example, I tried this, but I'm getting a ton of compilation errors:</p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
      // Some JavaScript code here to display map, etc.
  
      // Now add markers
      @foreach (var item in Model) {
  
          var markerlatLng = new google.maps.LatLng(@(Model.Latitude), @(Model.Longitude));
          var title = '@(Model.Title)';
          var description = '@(Model.Description)';
          var contentString = '&lt;h3&gt;' + title + '&lt;/h3&gt;' + '&lt;p&gt;' + description + '&lt;/p&gt;'
  
          var infowindow = new google.maps.InfoWindow({
              content: contentString
          });
  
          var marker = new google.maps.Marker({
              position: latLng,
              title: title,
              map: map,
              draggable: false
          });
  
          google.maps.event.addListener(marker, 'click', function () {
              infowindow.open(map, marker);
          });
      }
  &lt;/script&gt;
  </code></pre>