1

私の Web ページ / ビューには、1 つから多数のインポート レコードがあります。各インポート レコード内には、次の 0 から多数のものがあります。

  • 注文書
  • 輸送用コンテナ
  • 製品
  • 請求書

ビューモデルを次のようにコーディングしました。

namespace LemansCorpIntranet.Models
{    
    public class ImportWebViewModel
    {
        public string button { get; set; }
        public string status_filter { get; set; }
        public string import_id_filter { get; set; }
        public DateTime date_filter { get; set; }
        public string vendor_filter { get; set; }
        public string port_filter { get; set; }
        public string whse_filter { get; set; }
        public Boolean not_released_filter { get; set; }
        public int release_gap { get; set; }
        public List<import_row> import_rows;
    }

    public class import_row
    {
        public string update_switch { get; set; }
        public string id { get; set; }
        public IEnumerable<SelectListItem> ship_via { get; set; }
        public string broker_number { get; set; }
        public string voyage { get; set; }
        public string vessel { get; set; }
        public decimal shipment_value { get; set; }
        public int cartons { get; set; }
        public decimal weight { get; set; }
        public decimal volume { get; set; }
        public string clearance_port { get; set; }
        public string warehouses_in_shipment { get; set; }
        public string payment_type { get; set; }
        public string insurance { get; set; }
        public DateTime ship_date { get; set; }
        public DateTime close_date { get; set; }
        public DateTime customs_date { get; set; }
        public string customs_entry { get; set; }
        public DateTime pl_2_whse_date { get; set; }
        public DateTime estimated_arrival_date { get; set; }
        public DateTime wire_transfer_request_done_date { get; set; }
        public DateTime approved_broker_bill_date { get; set; }
        public DateTime product_released_date { get; set; }
        public List<Invoice> Invoices;
        public List<PurchaseOrder> PurchasOrders;
        public List<Product> Products;
        public List<Container> Containers;
    }

    public class Invoice
    {
        public string invoice_number { get; set; }
    }

    public class PurchaseOrder
    {
        public string id { get; set; }
        public string whse { get; set; }
        public string vendor_code { get; set; }
        public string vendor_name { get; set; }
    }

    public class Product
    {
        public int line_number { get; set; }
        public string description { get; set; }
    }

    public class Container
    {
        public int line_number { get; set; }
        public int size { get; set; }
        public string id { get; set; }
        public string seal { get; set; }
        public DateTime received_date { get; set; }
        public int cartons { get; set; }
    }  
}

上記でよろしいでしょうか?クラスは正しくネストされていますか?

サーバーからのデータを正しく表示するビューを取得できますが、フォームを「投稿」すると、ネストされたクラスのデータが null になります。

これは、入力コントロールが必要に応じて構築されていないためだと思います。

私の見解は次のようなものです。

<table>
<% if (Model.import_rows != null)
   { %>
<%    for (int row = 0; row < Model.import_rows.Count; row++)
      { %>
        <tr><td>
                <%=Html.HiddenFor(x=>x.import_rows[row].id) %>
                <%=Html.TextBoxFor(x => x.import_rows[row].id)%>
            </td>
        </tr>
<%    } %>
<% } %>
</table>

どんな提案でも大歓迎です....

更新:「hiddenFor」アイテムを含めるようにビューを変更しました。

"import_rows" はコントローラーで null ではなくなりましたが、カウントは "0" です。まだ何か足りないはず……。

前もって感謝します。

4

1 に答える 1

0

RedirectToActionでビューモデルを渡そうとしていました。

これがそのように機能しないことを発見しました。

皆様のご協力に感謝いたします。

于 2012-09-25T21:52:04.223 に答える