![](/img/trans.png)
[英]How can I map tables using fluent API in ASP.NET MVC 5, Entity Framework 6?
[英]Using Google Map in asp.net mvc Entity Framework
我想将Google Map集成到Asp.net mvc实体框架中。 我想根据位置搜索条件将控制器的纬度和经度传递到视图,该部分正在工作,但是我不知道如何根据控制器的返回值动态地将其传递给Javascript部分,即纬度和经度。 请帮助解决我的问题。
HomeController.cs
LocationDbEntities dbentity = new LocationDbEntities();
public ActionResult Index()
{
int id = 2;
var query = dbentity.LocationDetails.First(c => c.Id == id);
return View("Index", query);
}
索引检视
@model MvcApplication2.Models.LocationDetail
@{
ViewBag.Title = "Index";
Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2>Index</h2>
<p>@Model.Latitude </p>
<p>@Model.Longitude</p>
<div id="map_canvas" style="width: 640px; height: 480px;">
</div>
_Layout.cshtml
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
$(document).ready(function () {
initialize();
});
function initialize() {
var mapOptions = {
center: new google.maps.LatLng(17.897400, 77.519500),
zoom: 10,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("map_canvas"),
mapOptions);
// create a marker
var latlng = new google.maps.LatLng(6.9167, 79.8473);
var marker = new google.maps.Marker({
position: latlng,
map: map,
title: 'My Place'
});
}
</script>
您可以从Model属性中的脚本标记内设置JavaScript变量,如下所示。
<script>
var myLat = '@Model.Latitude';
var myLong = '@Model.Longitude';
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.