我将尝试从我的控制器将一个JSON列表传递到视图中,但是我似乎缺少了一个关键的部分。以下是控制器的方法:
public ActionResult GetList()
{
var model = new ViewModel();
model.Places = new List<Place>
{
new Place() {Id = 1, Catch = "Gädda", PlaceName = "Arboga", GeoLat = 59.394861, GeoLong = 15.854361},
new Place() {Id = 2, Catch = "Aborre", PlaceName = "Fis", GeoLat = 59.394861, GeoLong = 15.845361}
};
return Json(model.Places, JsonRequestBehavior.AllowGet);
}
这是我想要发送JSON列表的视图中的变量:
var data = [];
有没有关于如何开始的提示?我真的不知道从哪里开始。谢谢!
为了简单起见,假设我在视图中有一个按钮调用 GetList()
编辑: 查询API的代码:
// Using the JQuery "each" selector to iterate through the JSON list and drop marker pins
$.each(data, function (i, item) {
var marker = new google.maps.Marker({
'position': new google.maps.LatLng(item.GeoLong, item.GeoLat),
'map': map,
'title': item.PlaceName
});
(在这里我应该补充一下,这段代码来自教程:http://www.codeproject.com/Articles/629913/Google-Maps-in-MVC-with-Custom-InfoWindow)