Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用Google Maps API绑定到.ADO模型时出错_C#_Asp.net Mvc 3_Razor_Google Maps Api 2 - Fatal编程技术网

C# 使用Google Maps API绑定到.ADO模型时出错

C# 使用Google Maps API绑定到.ADO模型时出错,c#,asp.net-mvc-3,razor,google-maps-api-2,C#,Asp.net Mvc 3,Razor,Google Maps Api 2,为什么会出现此错误? 编译器错误消息:CS1061:“System.Collections.Generic.IEnumerable”不包含“lat”的定义,并且找不到接受“System.Collections.Generic.IEnumerable”类型的第一个参数的扩展方法“lat”(是否缺少using指令或程序集引用?) .Ado模型 内部、横向、液化天然气、内容物 控制器 using System; using System.Collections.Generic; using Syste

为什么会出现此错误?

编译器错误消息:CS1061:“System.Collections.Generic.IEnumerable”不包含“lat”的定义,并且找不到接受“System.Collections.Generic.IEnumerable”类型的第一个参数的扩展方法“lat”(是否缺少using指令或程序集引用?)

.Ado模型
内部、横向、液化天然气、内容物

控制器

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MapApp.Models;

namespace MapApp.Controllers
{
    [HandleError]
    public class HomeController : Controller
    {
        mapEntities _db = new mapEntities();

        public ActionResult Index()
        {
            return View(_db.river);
        }

        public ActionResult About()
        {
            return View();
        }
    }
}
public class HomeController : Controller
{
    mapEntities _db = new mapEntities();

    public ActionResult Index()
    {
        return View(_db.river.ToList());
    }
}
查看

@model IEnumerable<MapApp.Models.river>
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
<h2> Index</h2>
<script type="text/javascript">
@foreach (var item in Model)
{
    <text>
      var markerlatLng = new google.maps.LatLng(@(Model.lat), @(Model.lng));
      var contents = '@(Model.contents)';

      var infowindow = new google.maps.InfoWindow({
          content: contents
      });

      var marker = new google.maps.Marker({
          position: markerlatLng,
          title: contents,
          map: map,
          draggable: false
      });

      google.maps.event.addListener(marker, 'click', function () {
          infowindow.open(map, marker);
      });

   </text>
}
</script>
@model IEnumerable
@{
ViewBag.Title=“Index”;
Layout=“~/Views/Shared/_Layout.cshtml”;
}
指数
@foreach(模型中的var项目)
{
var markerlatng=新的google.maps.LatLng(@(Model.lat),@(Model.lng));
var contents='@(Model.contents)';
var infowindow=new google.maps.infowindow({
内容:内容
});
var marker=new google.maps.marker({
职位:markerlatLng,
标题:目录,
地图:地图,
可拖动:错误
});
google.maps.event.addListener(标记,'click',函数(){
信息窗口。打开(地图、标记);
});
}

模型
是可枚举的
河流
s。看起来您在河流中的循环是正确的,但是您在循环中错误地引用了每个项目

尝试:


这应该可以解决问题。

模型
是一个可枚举的
s。看起来您在河流中的循环是正确的,但是您在循环中错误地引用了每个项目

尝试:

那应该可以了。

修好了

控制器

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MapApp.Models;

namespace MapApp.Controllers
{
    [HandleError]
    public class HomeController : Controller
    {
        mapEntities _db = new mapEntities();

        public ActionResult Index()
        {
            return View(_db.river);
        }

        public ActionResult About()
        {
            return View();
        }
    }
}
public class HomeController : Controller
{
    mapEntities _db = new mapEntities();

    public ActionResult Index()
    {
        return View(_db.river.ToList());
    }
}
查看

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">

$(function () {
    var latLng = new google.maps.LatLng(52.379397, 4.889644); // Amsterdam
    var map = new google.maps.Map(document.getElementById('map-canvas'), {
        zoom: 15,
        center: latLng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    });

    function addMarker(latitude, longitude, title)
    {
        var markerLatLng = new google.maps.LatLng(latitude, longitude);
        var title = title;

        var marker = new google.maps.Marker({
            position: markerLatLng,
            title: title,
            map: map,
            draggable: false
        });
    };

   @foreach (var item in Model)
   {  
     @:addMarker(@item.latitude, @item.longitude, "@item.title");
   }

}); 

</script>
<div id="map-canvas">
</div>

$(函数(){
var latLng=new google.maps.latLng(52.379397,4.889644);//阿姆斯特丹
var map=new google.maps.map(document.getElementById('map-canvas'){
缩放:15,
中心:拉特林,
mapTypeId:google.maps.mapTypeId.ROADMAP
});
函数addMarker(纬度、经度、标题)
{
var markerlatng=new google.maps.LatLng(纬度、经度);
var title=标题;
var marker=new google.maps.marker({
职位:markerLatLng,
标题:标题,,
地图:地图,
可拖动:错误
});
};
@foreach(模型中的var项目)
{  
@:addMarker(@item.latitude、@item.longitude、@item.title”);
}
}); 
修好了

控制器

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using MapApp.Models;

namespace MapApp.Controllers
{
    [HandleError]
    public class HomeController : Controller
    {
        mapEntities _db = new mapEntities();

        public ActionResult Index()
        {
            return View(_db.river);
        }

        public ActionResult About()
        {
            return View();
        }
    }
}
public class HomeController : Controller
{
    mapEntities _db = new mapEntities();

    public ActionResult Index()
    {
        return View(_db.river.ToList());
    }
}
查看

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">

$(function () {
    var latLng = new google.maps.LatLng(52.379397, 4.889644); // Amsterdam
    var map = new google.maps.Map(document.getElementById('map-canvas'), {
        zoom: 15,
        center: latLng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    });

    function addMarker(latitude, longitude, title)
    {
        var markerLatLng = new google.maps.LatLng(latitude, longitude);
        var title = title;

        var marker = new google.maps.Marker({
            position: markerLatLng,
            title: title,
            map: map,
            draggable: false
        });
    };

   @foreach (var item in Model)
   {  
     @:addMarker(@item.latitude, @item.longitude, "@item.title");
   }

}); 

</script>
<div id="map-canvas">
</div>

$(函数(){
var latLng=new google.maps.latLng(52.379397,4.889644);//阿姆斯特丹
var map=new google.maps.map(document.getElementById('map-canvas'){
缩放:15,
中心:拉特林,
mapTypeId:google.maps.mapTypeId.ROADMAP
});
函数addMarker(纬度、经度、标题)
{
var markerlatng=new google.maps.LatLng(纬度、经度);
var title=标题;
var marker=new google.maps.marker({
职位:markerLatLng,
标题:标题,,
地图:地图,
可拖动:错误
});
};
@foreach(模型中的var项目)
{  
@:addMarker(@item.latitude、@item.longitude、@item.title”);
}
});