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

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

數(shù)據(jù)不是從JsonResult Action到Javascript腳本

數(shù)據(jù)不是從JsonResult Action到Javascript腳本

三國紛爭 2021-05-10 08:09:50
如標(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嗎?任何幫助將不勝感激。
查看完整描述

2 回答

?
汪汪一只貓

TA貢獻(xiàn)1898條經(jīng)驗 獲得超8個贊

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

return Json(data, JsonRequestBehavior.AllowGet)


查看完整回答
反對 回復(fù) 2021-05-13
  • 2 回答
  • 0 關(guān)注
  • 280 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號

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