将对象列表从控制器传递到 MVC4 中的视图
Passing list of objects from controller to View in MVC4
我是ASP/MVC的新手,作为其中的一部分,我开始使用一个简单的应用程序进行学习。
我在控制器中有一个对象集合,如下所示
public ActionResult loadimage(String FQDN, String trange)
{
List<geo_crd> Geo_crd = new List<geo_crd>();
//more logic
foreach (ToDoItem T in query1)
{
IEnumerable<GeoItem> query2 = (from b in db1.GeoItems
where b.DNS_server_address == T.DNS_server_address
select b);
foreach (GeoItem X in query2)
{
Geo_crd.Add(new geo_crd(X.DNS_latitude, X.DNS_longitude, 1));
}
}
return View(Geo_crd);
}
Geo_crd在模型中如下所示
namespace ToDoApp.Models
{
public class geo_crd
{
private Decimal _geo_lat;
private Decimal _geo_long;
private int _status_flag;
public geo_crd(Decimal x, Decimal y, int z)
{
_geo_lat = x;
_geo_long = y;
_status_flag = z;
}
public Decimal geo_lat
{
get { return _geo_lat; }
set { _geo_lat = value; }
}
public Decimal geo_long
{
get { return _geo_long; }
set { _geo_long = value; }
}
public int status_flag
{
get { return _status_flag; }
set { _status_flag = value; }
}
}
}
我收到的意见如下
@model IEnumerable <ToDoApp.Models.geo_crd>
// more code here
<script type="text/javascript">
@foreach (var item in Model){
<spam><li> @item.geo_lat </li></spam>
<span> <li> AddLocationPin(@item.geo_lat, @item.geo_long, null, 'place 1');</li> </span>
}
</script>
我遇到的问题是,服务器没有发送AddlocatioPin,我猜它只是忽略了它。
我真的在做傻事吗?请帮忙
你不应该用 script
来包装 html 标签。开始和结束标记,它们的顺序也必须在 html 中匹配。另外,您应该阅读有关HTML ul标签的更多信息
正确的观点是
@model IEnumerable <ToDoApp.Models.geo_crd>
//more code here
<ul>
@foreach (var item in Model)
{
<li><span>@item.geo_lat </span></li>
<li><span>AddLocationPin(@item.geo_lat, @item.geo_long, null, 'place 1'); </span> </li>
}
</ul>
相关文章:
- 如何使用javascript从主svg对象动态创建svg视图框
- 正在使用$location.path(.)路由ng视图
- angular.js没有'无法在PhoneGap中处理视图标记
- 如何包含特定于每个视图angularjs的javascript文件
- 通过在Dojo mobile ViewController.openExternalView中动态更改打开同一外部视图的
- Kendo:我该如何在树视图中创建一个递归的hieiarchy
- 有没有可能在asp-mvc4中使用ajax呈现的视图中包含javascript
- 如何将Javascript数组传递给视图?(MVC4)
- MVC4 部分视图 JavaScript 捆绑问题
- 将对象列表从控制器传递到 MVC4 中的视图
- 如何在 asp.net MVC4 中将模型从视图传递到 javascript
- 如何在 MVC4 中使用 Razor 视图在表中创建动态行
- mvc4中所有视图的通用javascript验证
- 如何在MVC4中添加按钮并重定向到另一个视图
- 如何检查模型值在视图模型从Javascript在MVC4
- MVC4视图未检测到JQuery
- 如何在mvc4中从视图发送多个参数到API控制器
- ASP.. NET MVC4视图模型变更跟踪使用knockout.js
- 我可以用ASP发送消息而不是视图作为ActionResult返回吗?净MVC4
- MVC4部分视图导航器.userAgent问题