![](/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.