如何使一个表从列表MVC? [英] How do I make a table from a List MVC?
本文介绍了如何使一个表从列表MVC?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个名单(姓名,项目,组#),我想在一个表中显示。如何显示该数据与第一行中的第二所有名字,物品,和组号的第三行中的
I have a List(Name, Item, Group#) that I would like to display in a table. How do I display this data with all the names in the 1st row, item in the 2nd, and group number in the 3rd row.
名称:|乔恩|汤姆|凯特|布莱恩|
Name: | Jon | Tom | Kate | Brian |
项目:|杯|帽子|门|商店|
Item: | Cup | Hat | Door | Store |
组#:| 2 | 8 | 10 | 154 |
Group#:| 2 | 8 | 10 | 154 |
推荐答案
由于你会水平,而不是垂直,这使我想到了一个有点乱了code例子。我不知道是否有替代这一点,但这应该工作。
Because you're going horizontally instead of vertically, this makes the code example I've thought up a bit messy. I'm not sure if there's an alternative to this, but this should work.
<table class="table">
<tr>
<td>
Name
</td>
<%
foreach (var item in Model)
{
%>
<td>
<%= item.Name %>
</td>
<%
}
%>
</tr>
<tr>
<td>
Item
</td>
<%
foreach (var item in Model)
{
%>
<td>
<%= item.Item %>
</td>
<%
}
%>
</tr>
<tr>
<td>
Group
</td>
<%
foreach (var item in Model)
{
%>
<td>
<%= item.Group%>
</td>
<%
}
%>
</tr>
</table>
这篇关于如何使一个表从列表MVC?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文