我的网页/视图将有 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; }
}
}
以上可以吗?类是否正确嵌套?
我可以让视图正确显示来自服务器的数据,但是当我“发布”表单时,嵌套类中的数据为空。
我相信这是因为输入控件没有按需要构建。
我的观点类似于以下:
<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”在控制器中不再为空,但计数为“0”。我仍然必须错过一些东西......
提前致谢。