简体   繁体   English

MVC3-模型到HTML表

[英]MVC3 - Model to HTML table

I have an OfferingCategoriesViewModel which contains a list of OfferingCategoryModel's. 我有一个提供类别视图模型,其中包含一个提供类别模型的列表。

How I can display each OfferingCategoryModel in my view so it looks like below 如何在我的视图中显示每个OfferCategoryModel,如下所示

http://imgur.com/8fsEg

Note: Ideally I want the number of models to display per row to be included in the OfferingCategoriesViewModel. 注意:理想情况下,我希望每行显示的模型数量包含在OfferCategories类别模型中。

I currently have this: 我目前有这个:

<table>
    @foreach (var item in Model)
    {
        <tr>
            @foreach (Spice.TimeBank.Models.Category.OfferingCategoryModel category in Model.ListOfCategories)
            {
                <td>@category.Descripton</td>
            }
            -->
            @for (int i = item.Count(); i < 5; i++)
            {
                <td></td>
            }
        </tr>
    }
</table>

I know you are describing the use of tables for that layout, but I would actually recommend going for <div> blocks with a layout using css float: left; 我知道您正在描述使用该布局的表,但实际上我建议您使用css float: left;进行布局的<div>float: left; , to get an self-arranging layout depending on user screen resolution and window size. ,以根据用户屏幕分辨率和窗口大小获得自动排列的布局。

That way you avoid having to worry about how many columns to display, and the html and styles becomes cleaner. 这样,您就不必担心要显示多少列,并且html和样式变得更整洁。

In fact, if you design it that way, you can just create a single MVC DisplayTemplate rendering each div for that model, and have MVC worry about iterating through your items. 实际上,如果以这种方式进行设计,则可以只创建一个MVC DisplayTemplate呈现该模型的每个div,并使MVC担心迭代您的项目。

EDIT: Here you can find more info on how to use float : The 4th tutorial might be of special interest, since it shows an example of a layout nearly identical to yours. 编辑: 在这里您可以找到有关如何使用float更多信息:第4教程可能会特别令人感兴趣,因为它显示了与您的布局几乎相同的布局示例。

Also here's another very good source of good info using floating elements, with visual examples as well. 这也是使用浮动元素另一个很好信息的很好来源,还提供了可视示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM