第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

數(shù)據(jù)不是來(lái)自 JsonResult Action 到 Javascript 腳本

數(shù)據(jù)不是來(lái)自 JsonResult Action 到 Javascript 腳本

C#
楊魅力 2022-12-31 14:06:14
正如標(biāo)題所說(shuō),我無(wú)法在我的 javascript 中獲取和使用數(shù)據(jù)庫(kù)中的數(shù)據(jù)。我有一個(gè)控制器,其中有我的數(shù)據(jù)庫(kù)上下文構(gòu)造函數(shù)和一個(gè) JsonResult 操作,其中信息按原樣出現(xiàn),但是當(dāng)我嘗試在 javascript 中使用數(shù)據(jù)時(shí),我相信它是空的。這是我的控制器: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 回答

?
慕容3067478

TA貢獻(xiàn)1773條經(jīng)驗(yàn) 獲得超3個(gè)贊

我認(rèn)為您需要JsonRequestBehavior.AllowGet在方法中添加作為第二個(gè)參數(shù)Json()。

return Json(data, JsonRequestBehavior.AllowGet)


查看完整回答
反對(duì) 回復(fù) 2022-12-31
?
阿晨1998

TA貢獻(xiàn)2037條經(jīng)驗(yàn) 獲得超6個(gè)贊

解決。問(wèn)題是return Json(data)返回一個(gè)字符串,類似的東西{name: "x"},我試圖把它當(dāng)作data.Name我應(yīng)該做的data.name,因?yàn)樗鼇?lái)自 json。



查看完整回答
反對(duì) 回復(fù) 2022-12-31
  • 2 回答
  • 0 關(guān)注
  • 120 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)