[英]Passing list of objects from controller to View in MVC4
I am new to ASP/MVC and as part of that started learning using a simple app. 我是ASP / MVC的新手,因此开始使用一个简单的应用程序学习。
I have a collection of objects as below in the controller 我在控制器中有以下对象的集合
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 is in models as follows 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; }
}
}
}
I am receiving in the views as follows 我收到以下意见
@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>
the issue I am having is , the server is not sending the AddlocatioPin , it is just ignoring it I guess. 我遇到的问题是,服务器未发送AddlocatioPin,我猜只是忽略了它。
am i doing something really stupid ? 我在做些很愚蠢的事情吗? please help 请帮忙
You should not wrap html tags with script
. 您不应该使用script
包装html标记。 Start and end tags, also their order must match in html. 开始和结束标记,它们的顺序也必须在html中匹配。 Also you should read more about HTML ul tag 您还应该阅读有关HTML ul标签的更多信息
Correct view would be 正确的看法是
@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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.