title: How to call JavaScript function in Razor
body: <p>I've created an array and pass it to view with ViewBag.</p>
  
  <pre><code>ViewBag.MarkerList = Utility.markerList; 
  </code></pre>
  
  <p>And I have a function to add a marker on map in JavaScript:</p>
  
  <pre><code>function myFunction(item) {
      var marker = L.marker([item.lat, item.lng], { riseOnHover: true }).addTo(mymap);
      marker.bindPopup("I am a popup.&lt;br&gt;"+ item.lat + "," + item.lng);
  }
  var array = @ViewBag.MarkerList;
  
          array.foreach(myFunction);
  </code></pre>
  
  <p>How can I use foreach in ViewBag and call the JavaScript function?</p>