正如標題所說,我無法在我的 javascript 中獲取和使用數據庫中的數據。我有一個控制器,其中有我的數據庫上下文構造函數和一個 JsonResult 操作,其中信息按原樣出現,但是當我嘗試在 javascript 中使用數據時,我相信它是空的。這是我的控制器:namespace ProiectColectiv.Controllers{ public class AdminMapController : Controller { private readonly ProiectColectivContext _context; public AdminMapController(ProiectColectivContext context) { _context = context; } public ActionResult AdminMap(User user) { return View("~/Views/Home/AdminMap.cshtml", user); } public JsonResult GetAllLocation() { var data = _context.Parkings.ToList(); return Json(data); } }}這是我的 .cshtml 和 javascript:@*@model ProiectColectiv.Models.Parking*@@{ ViewData["Title"] = "Admin Map";}<br/><!DOCTYPE html><html><head> <meta name="viewport" content="initial-scale=1.0"> <meta charset="utf-8"> <style> /* Always set the map height explicitly to define the size of the div * element that contains the map. */ #map { height: 800px; width: 1200px; } </style> </head><body><div id="map"></div><script> var map; function initMap() { map = new google.maps.Map(document.getElementById('map'), { center: { lat: 46.770920, lng: 23.589920}, zoom: 13 }); $.get("@Url.Action("GetAllLocation","AdminMap")", function (data, status) { var marker = []; var contentString = []; var infowindow = []; for (var i = 0; i < data.length; i++) { marker[i] = new google.maps.Marker({ position: { lat: parseFloat(data[i].Latitudine), lng: parseFloat(data[i].Longitudine) }, map: map });
- 2 回答
- 0 關注
- 114 瀏覽
添加回答
舉報
0/150
提交
取消