【发布时间】:2013-11-06 21:45:31
【问题描述】:
我正在尝试使用从数据库中提取的数据制作一个 HTML 表...
这是我的模型...
public class PopulationModels
{
public List<PopulationModel> Populations { set; get; }
}
这只是一个...的列表
public class PopulationModel
{
public string populationID { set; get; }
public string PopName { set; get; }
public string Description { set; get; }
public string PopulationType { set; get; }
public Boolean isActive { set; get; }
//public List<XSLTACOData> patients { set; get; }
}
我像这样将这个模型传递给我的视图......
IEnumerable<PopulationModels> PopModel = DataRepo.Get(userName);
return View(PopModel);
我尝试通过以下方式显示列表...
@foreach (var item in Model) {
<tr>
<td class="rowControl hidden">
@*<a href="#makeRowEditable" class="makeRowEditable">Edit</a>*@ |
@*<a href="#deleteRow" class="deleteRow">Delete</a>*@
@Html.DispalyFor(modelItem => item.Populations)
</td>
</tr>
}
但我很难弄清楚如何访问我的模型的各个元素...
例如
@Html.DispalyFor(modelItem => item.Populations)
上面的代码行,我想获取每个单独的 populationModel 并为每个字段映射一列...但我似乎无法访问各个人口...我在这里错过了一个合乎逻辑的步骤吗(我显然是,但哪一步?)
更新:添加更多视图:我现在正在制作一张桌子,但我这样做的方式似乎违反直觉......
这是我的模型...
@model IEnumerable<FocusedReadMissionsRedux.Models.PopulationModels>
以下是我创建表格的方式(我计划在获得可靠的数据访问方式后立即使用 jqGrid 的 tableToGrid 功能...
<table border="2">
<thead>
<tr>
<th>
Population Name
</th>
<th>
Population Description
</th>
</tr>
</thead>
@foreach(var item in Model){
foreach (var pop in item.Populations)
{
<tr>
<td class="rowControl hidden">
@Html.DisplayFor(modelItem => pop.PopName)
@Html.ActionLink(pop.PopName,"","")
</td>
<td>
@Html.DisplayFor(modelItem => pop.Description)
@Html.Display(pop.Description)
</td>
</tr>
}
}
【问题讨论】: