显示来自不同表MVC4的html表上的数据

时间:2014-01-27 05:04:05

标签: asp.net-mvc-4 viewmodel

我有一个html表,我需要显示不同表中的不同数据。

这是表格:

enter image description here

我在这里使用了viewmodel,我能够显示一些数据,但我需要显示所有内容。

如何显示Delivery,Collection和Proposal表中的数据?

这是我的viewmodel:

public class FulfillmentViewModel
{
    [Key]
    public int ID { get; set; }

    public IEnumerable<ULIV.Models.ProductModel> Product { get; set; }

    public IEnumerable<ULIV.Models.ProposalModel> Proposal { get; set; }

    public IEnumerable<ULIV.Models.PurchaseOrder> PurchaseOrder { get; set; }

    public IEnumerable<ULIV.Models.Delivery> Delivery { get; set; }

    public IEnumerable<ULIV.Models.Collection> Collection { get; set; }

    public IEnumerable<Institution> Institution { get; set; }

}

这是我在VIEW上的代码:

<table class="table table-bordered table-hover">
                    <thead>
                        <tr class="th-center">
                            <th colspan="2">Product</th>
                            <th colspan="3">Purchase Order</th>
                            <th colspan="2">Delivery</th>
                            <th colspan="2">Collection</th>
                            <th rowspan="2">Action</th>
                        </tr>
                        <tr class="th-center">
                            <th>Name</th>
                            <th>Proposal Code</th>
                            <th>PO Number</th>
                            <th>PO Date</th>
                            <th>Received Date</th>
                            <th>SI Number</th>
                            <th>Delivery Date</th>
                            <th>OR Number</th>
                            <th>OR Date</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach(var PO in Model.PurchaseOrder)
                        {
                        <tr>
                            <td>Anflu</td>
                            <td></td>
                            <td><a href="fulfillment–delivery-and-collection-details.html">@Html.DisplayFor(modelItem => PO.PurchaseOrderNo)</a></td>
                            <td>@Html.DisplayFor(modelItem => PO.PurchaseOrderDate)</td>                                                                                                
                            <td>@Html.DisplayFor(modelItem => PO.ReceivedDate)</td>
                            <td>SI-0002314</td>
                            <td>December 20, 2013</td>
                            <td>-</td>
                            <td>-</td>
                            <td class="text-center">
                                <a href="edit-purchase-order.html"><img src="Images/icon_edit.png" width="16" height="16"></a>
                                <a href="new-delivery.html"><img src="Images/icon-delivery.png" width="16" height="16"></a>
                                <a href="new-collection.html"><img src="Images/icon-collection.png" width="16" height="16"></a>
                            </td>
                        </tr>
                        }



                    </tbody>
                </table>

1 个答案:

答案 0 :(得分:0)

一种解决方案是将DeliveryCollectionProposal合并到一个单独的类中,然后在ViewModel中包含这个新类。然后,您可以通过ItemModel枚举,并能够访问相关的ProductDeliveryCollection

public class ItemModel
{
    public ULIV.Models.ProductModel Product { get; set; }
    public ULIV.Models.Delivery Delivery { get; set; }
    public ULIV.Models.Collection Collection { get; set; }
}

public class FulfillmentViewModel
{
    [Key]
    public int ID { get; set; }

    public IEnumerable<ULIV.Models.ItemModel> Items { get; set; }

    public IEnumerable<ULIV.Models.ProposalModel> Proposal { get; set; }

    public IEnumerable<ULIV.Models.PurchaseOrder> PurchaseOrder { get; set; }

    public IEnumerable<Institution> Institution { get; set; }

}