开发者

How do I make a table from a List 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 开发者_如何学C3rd row.

Name: | Jon | Tom | Kate | Brian |

Item: | Cup | Hat | Door | Store |

Group#:| 2 | 8 | 10 | 154 |


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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜