0

i have a viewdata in contoller as follows

 namespace GeoPortal.Controllers
 {
public class FarmsController : Controller
{
    GeoPortalEntities db = new GeoPortalEntities();
    // GET: Farms
    public ActionResult Index()
    {
        var model = db.Farms;

        var mylist = db.Farms.ToList();
        ViewData["Farms"] = mylist; // Send this list to the view

        return View(model.ToList());

    }



}
}

i want to pass this list to my view and have it rendered of google maps. i want to have a for loop statement that will pick up addresses from viewdata that is passed to the front end

   @using (Html.BeginForm())
  {
 <head>
<style>
    #map {
        height: 100px;
        width: 100%;
    }
</style>
 </head>
  <body>
<div id="map"></div>
<script>
  function initMap() {
    var uluru = {lat: -25.363, lng: 131.044};
    var map = new google.maps.Map(document.getElementById('map'), {
      zoom: 4,
      center: uluru
    });
    var marker = new google.maps.Marker({
      position: uluru,
      map: map
    });
  }
</script>
<script async defer
        src="https://maps.googleapis.com/maps/api/js?
  key=AIzaSyDMg_EyG8kqEaPXS0Gn-67UzA4z7fpfBQg&callback=initMap">
</script>
 </body>
 }
  • Possible duplicate of [Using Razor within JavaScript](https://stackoverflow.com/questions/4599169/using-razor-within-javascript) – Kenzo_Gilead Sep 17 '17 at 14:34

1 Answers1

0

You can do your logic inside <text> pseudo-element.

Check this question Using Razor within JavaScript

Eduardo Carísio
  • 415
  • 1
  • 5
  • 14