我有一个包含我的模型列表的 ViewModel,如下所示:
public class OrderConfirm
{
public ICollection<DayBookQuoteLines> SalesLines { get; set; }
public ICollection<DayBookQuoteLines> LostLines { get; set; }
public string Currency { get; set; }
}
然后我在我的视图中使用这个 ViewModel,如下所示:
@model btn_intranet.Areas.DayBook.Models.ViewModels.OrderConfirm
@{
ViewBag.Title = "Daybook - Order Confirmation";
}
<h6>Sales Lines</h6>
<div id="SalesOrders">
@using (Ajax.BeginForm("ConfirmSalesOrder", new AjaxOptions()
{
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "SalesOrders",
OnBegin = "SalesOrderConfirm"
}))
{
@foreach(var item in Model.SalesLines)
{
<p>@item.ItemName</p>
<p>@item.Qty</p>
@* Other Properties *@
}
<input type="submit" value="Submit Sales Order" />
}
</div>
<h6>Lost Lines</h6>
<div id="LostOrders">
@using (Ajax.BeginForm("ConfirmLostOrder", new AjaxOptions()
{
InsertionMode = InsertionMode.Replace,
UpdateTargetId = "LostOrders",
OnBegin = "LostOrderConfirm"
}))
{
@foreach(var item in Model.SalesLines)
{
<p>@item.ItemName</p>
<p>@item.Qty</p>
@* Other Properties *@
}
<input type="submit" value="Submit Lost Order" />
}
</div>
问题是,在我的[HttpPost]
行动中,ConfirmSalesOrder
和ConfirmLostOrder
. 作为参数传递的我的模型的值为空:
[HttpPost]
public ActionResult ConfirmSalesOrder(List<DayBookQuoteLines> quoteLines)
{
// Process order...
return PartialView("Sales/_ConfirmSalesOrder");
}
quoteLines
空值也是如此。如何将表单绑定到我的模型?