问题描述
我在尝试与数据的HTML表我拉出来的DB ...
I am attempting to make an HTML Table with data I pull out of DB...
下面是我的模型......
Here is my Model...
public class PopulationModels
{
public List<PopulationModel> Populations { set; get; }
}
这是一个简单的...列表
Which is simply a list of...
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; }
}
我这个模型传递给我的看法是这样的...
I pass this model to my view like so...
IEnumerable<PopulationModels> PopModel = DataRepo.Get(userName);
return View(PopModel);
我试图以下列方式来显示一个列表...
I attempt to show a list in the following way...
@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>
}
不过,我有一个很难搞清楚如何来访问我的模型的各个元素...
But I am having a hard time figuring out how to access the individual elements of my model...
例如
@Html.DispalyFor(modelItem => item.Populations)
code的上面一行,我想利用每一个人populationModel并映射每个字段的列...但我似乎无法访问个别人群......我缺少一个逻辑步骤这里(我明显感到,但哪一步?)
The above line of code, I want to take each individual populationModel and map a column for each of the fields... But I can't seem to access the individual populations... Am I missing a logical step here (I obviously am, but which step?)
更新:添加查看更多一些:我现在做一个获取表,但我做的方式似乎有点违背直觉...
UPDATE: ADDING SOME MORE OF THE VIEW: I am making now getting a table, but the way I am doing it seems counter intuitive...
下面是我的模型......
Here is my model...
@model IEnumerable<FocusedReadMissionsRedux.Models.PopulationModels>
这里是我如何创建我的表(我打算尽快使用的jqGrid的tableToGrid的功能,我可以得到一个坚实的方式来访问我的数据...
Here is how I am creating my table (I am planning on using jqGrid's tableToGrid functionality as soon as I can get a solid way to access my data...
<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>
}
}
推荐答案
既然你没有张贴完整code你的观点:你应该定义什么样的对象要在你看来像这样绑定:
Since you didn't post the complete code for your view: you should define what kind of object you are binding to in your view like this:
@model IEnumerable<PopulationModels>
然后,你可以通过它循环在foreach和绑定使用当前项目:
Then you can just loop through it with a foreach and bind to the current item using:
@Html.DisplayFor(x => x.Popname)
这篇关于制作使用强类型模型MVC4 HTML表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!