如標(biāo)題所示,我無法從JavaScript中的數(shù)據(jù)庫中獲取和使用數(shù)據(jù)。我有一個控制器,其中有我的數(shù)據(jù)庫上下文構(gòu)造函數(shù)和一個JsonResult動作,其中的信息應(yīng)以其應(yīng)有的方式提供,但是當(dāng)我嘗試在JavaScript中使用數(shù)據(jù)時,我認(rèn)為它為null。這是我的控制器: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++) { 知道為什么數(shù)據(jù)不傳遞給javascript嗎?任何幫助將不勝感激。
數(shù)據(jù)不是從JsonResult Action到Javascript腳本
三國紛爭
2021-05-10 08:09:50