【问题标题】:Display data on html table from different tables MVC4在不同表MVC4的html表上显示数据
【发布时间】:2014-01-27 05:04:04
【问题描述】:

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

这是桌子:

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

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

这是我的视图模型:

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>

【问题讨论】:

    标签: asp.net-mvc-4 viewmodel


    【解决方案1】:

    一种解决方案是将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; }
    

    }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-10-14
      • 2014-08-20
      • 2020-06-03
      • 1970-01-01
      • 2012-08-15
      • 2012-04-10
      • 2020-06-18
      相关资源
      最近更新 更多