微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

url.content无法加载图像javascript和asp.net mvc

如何解决url.content无法加载图像javascript和asp.net mvc

我的视图中有JavaScript,并且我正尝试将数据库中的图片加载到Google地图的信息窗口中,但该图片无法加载。

视图中的Java代码

 $.get("@Url.Action("GetMarkers","Donator")",function (json,status) {

      //Global infoWindow object that will be reused by all markers
      var infoWindow = new google.maps.InfoWindow();
      var marker,data;

      //Loop through the json data
       for (var i = 0; i < json.length; i++) {
             data = json[i];
             var latLng = new google.maps.LatLng(data.Latitude,data.Longitude)
             //Creating marker and putting it on the map
             marker = new google.maps.Marker({
                  position: latLng,map: map,title: data.NpoName + ' says Click Me!'
       });

       // Creating a closure to retain the correct data,notice how I pass the current data in the loop into the closure (marker,data)
       (function (marker,data) {
             // Attaching a click event to the current marker
             google.maps.event.addListener(marker,"click",function (e) {
             var imageUrl = '<%=Url.Content(' + data.VerificationIcon + ')%>';
             infoWindow.setContent('<h3 class="info-window-title">' + data.NpoName + '</h3>' + '<hr />' + '<p>Npo type: ' + data.NpoType + '</p>' + '<p>' + data.VerificationStatus + '<img src="' + imageUrl + '" alt="verification icon" class="verification-icon" />' + '</p>' + '<a href="/Wallet/Wallet/' + @Model.DonatorID + '/' + data.NpoID + '">Click here to donate!</a>');
              infoWindow.open(map,marker);
         });

       })(marker,data);
    };
});

控制器中的代码

 public JsonResult GetMarkers()
{
     //disable lazy loading
     db.Configuration.ProxyCreationEnabled = false;

     //Map marker section
     var DynamicMapMarkers = db.tblNpo.Include(zz => zz.tblVerification).Include(xx => xx.tblNpo_Type);

     //Set map marker values
     foreach (var item in DynamicMapMarkers)
     {
         DonatorUserviewmodel MapMarkers = new DonatorUserviewmodel();

         MapMarkers.NpoID = item.npo_id;
         MapMarkers.NpoName = item.npo_name;
         MapMarkers.NpoType = item.tblNpo_Type.description;
         MapMarkers.VerificationStatus = item.tblVerification.description;
         MapMarkers.VerificationIcon = item.tblVerification.verification_icon;
         MapMarkers.Longitude = Convert.Todouble(item.longitude);
         MapMarkers.Latitude = Convert.Todouble(item.latitude);

         MapMarkerList.Add(MapMarkers);
      }

      var json = MapMarkerList;
      return Json(json,JsonRequestBehavior.AllowGet);
}

上面代码中的主要关注区域:

var imageUrl = '<%=Url.Content(' + data.VerificationIcon + ')%>';
infoWindow.setContent('<h3 class="info-window-title">' + data.NpoName + '</h3>' + '<hr />' + '<p>Npo type: ' + data.NpoType + '</p>' + '<p>' + data.VerificationStatus + '<img src="' + imageUrl + '" alt="verification icon" class="verification-icon" />' + '</p>' + '<a href="/Wallet/Wallet/' + @Model.DonatorID + '/' + data.NpoID + '">Click here to donate!</a>');

图像在数据库~/Images/DbImages/verified.png中的存储方式的格式

我不确定为什么无法加载图像,或者如何解决该图像。任何帮助将不胜感激。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。