2012-09-24 2 views
1

내 웹 페이지/뷰에는 1 - 많은 가져 오기 레코드가 있습니다. 중첩 클래스로 viewModel을 코딩하는 방법

  • 송장
  • 다음과 같이 내가보기 모델을 코딩 한

    • 구매 주문
    • 배송 컨테이너
    • 제품 : 각 수입 기록을 내 는 다음의 많은 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"입니다. 나는 아직도 뭔가를 놓치고 있어야합니다 .....

      미리 감사드립니다.

    +0

    모델을 병합하거나 각각의 '중첩 된'클래스의 모든 속성에 대해 숨김 필드를 만들거나 post 메소드로 돌아 왔을 때 데이터베이스에서 데이터를 다시 가져와야합니다. –

    답변

    0

    나는 RedirectToAction의 뷰 모델을 통과하려고 시도했습니다 ..

    이 그런 식으로 작동하지 않습니다 발견했다.

    귀하의 도움에 감사드립니다.

    관련 문제