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 (将#修改为@)