我的网页/视图将包含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”。 我仍然必须遗漏一些东西......
提前致谢。
答案 0 :(得分:0)
我试图在RedirectToAction中传递viewmodel ..
发现这不起作用。
感谢大家的帮助。