2017-09-16 106 views
0

我有一個位指示可視數據如下我如何通過可視數據從控制器查看JavaScript

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()); 

    } 



} 
} 

我想這個列表傳遞給我的看法,並將它呈現的谷歌地圖。我想有一個for循環語句將傳遞到前端

@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> 
} 
+0

[使用中的JavaScript剃刀]的可能的複製(https://stackoverflow.com/questions/4599169/using-razor-within-javascript) –

回答

相關問題