gpt4 book ai didi

c# - 使用 Google Maps API 绑定(bind)到 .ADO 模型时出错

转载 作者:太空宇宙 更新时间:2023-11-03 16:25:02 27 4
gpt4 key购买 nike

为什么会出现此错误?

Compiler Error Message: CS1061: 'System.Collections.Generic.IEnumerable' does not contain a definition for 'lat' and no extension method 'lat' accepting a first argument of type 'System.Collections.Generic.IEnumerable' could be found (are you missing a using directive or an assembly reference?)

.Ado 模型
国际、纬度、经度、内容

Controller

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>

最佳答案

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

尝试:

var markerlatLng = new google.maps.LatLng(@(item.lat), @(item.lng));
var contents = '@(item.contents)';

这应该可以解决问题。

关于c# - 使用 Google Maps API 绑定(bind)到 .ADO 模型时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12847095/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com