为什么我会收到此错误?
编译器错误消息:CS1061:“System.Collections.Generic.IEnumerable”不包含“lat”的定义,并且找不到接受“System.Collections.Generic.IEnumerable”类型的第一个参数的扩展方法“lat”(您是否缺少 using 指令或程序集引用?)
.Ado 模型
int, lat, lng, 内容
控制器
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();
}
}
}
看法
@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>