我在控制器中有一个viewdata如下
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循环语句,它将从传递给前端的viewdata中获取地址
@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>
}