我有一个应用程序调用Web服务来显示基于用户输入的标准的导入记录。MVC2控制器没有收到提交视图中的所有数据
每个“导入”可以有0到多个PurchaseOrder,0到很多容器,0到很多产品,0到很多发票。
查看(显示查询)工作正常,bur当我点击一个提交按钮控制器没有通过视图模型获取“导入”信息。我可以通过“formCollection”访问这些控件。
我在想什么?
这里是我的代码...
型号...
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; /// this is the piece that is not coming
// thru on the POST
}
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; }
}
}
这里是我的图(局部)
<% using (Html.BeginForm("ImportLog", "ImportWeb")) %>
<% { %>
<table style="position:fixed">
.
.
.
<% if (Model.import_rows != null) %>
<% { %>
<% var row_number = 0; %>
<table id="import_web_detail">
<% foreach (var row in Model.import_rows) %>
<% { %>
<% if (row.id != " ")%>
<% { %>
<% row_number++; %>
<tr style="vertical-align:top">
<td style="width:.5em" />
<td align="center">
<table>
<tr>
<td colspan="4"></td>
<td><%=Html.CheckBox("update_switch", row.update_switch)%></td>
<td colspan="4"></td>
</tr>
</table>
</td>
<td />
<td>
<table>
<tr>
<td><%=Html.TextBox("import_id", row.id)%></td>
</tr>
</table>
</td>
这是我的...位指示
namespace LemansCorpIntranet.Controllers
{
public class ImportWebController : Controller
{
eptest_importweb_svc.Service importweb_svc = new eptest_importweb_svc.Service();
//
// Import Web Request
public ActionResult ImportLog(ImportWebViewModel import_request)
{// import_request.import_rows is null. should be loaded with view detail
switch (import_request.button)
{
case "Next":
case "Previous":
return RedirectToAction("ImportPage", import_request);
case "Update":
return RedirectToAction("ImportUpdate");
case "Importlog":
return RedirectToAction("ImportReport");
default:
break;
}
// ----------------------------------
// fall thru for initial page display
// ----------------------------------
// load "date filter" with default. 300 days in the past.
// ------------------------------------------------------
import_request.date_filter = new DateTime(DateTime.Now.Year - 1,
DateTime.Now.Month, DateTime.Now.Day).AddDays(65);
return View("ImportLog", import_request);
}
我还没有发布完整的t他查看/控制器....
它的工作原理渲染视图....
当我提交视图/形成控制器只能访问的视图模型的主要部分(项目无在“列表”通过)。
我可以通过“formcollection”访问这些其他控件。
我想知道为什么viewmodel中有null。
这是很多代码。你能缩小到哪些项目没有通过帖子? –
我更新了上面的代码以削减代码.... – hyperstaff
您可能需要为每个“嵌套”类的每个属性隐藏一个元素。 –