【发布时间】:2013-05-29 14:13:32
【问题描述】:
我的 Razor 视图如下所示:
@model Namespace.Namespace.SupplierInvoiceMatchingVm
@using(Html.BeginForm("MatchLines", "PaymentTransaction"))
{
<table class="dataTable" style="width: 95%; margin: 0px auto;">
<tr>
<th></th>
<th>PO Line</th>
<th>Description</th>
</tr>
@for (var i = 0; i < Model.Lines.Count; i++)
{
<tr>
<td>@Html.CheckBoxFor(x => x.Lines[i].Selected)</td>
<td>@Html.DisplayFor(x =>x.Lines[i].LineRef) @Html.HiddenFor(x => x.Lines[i].LineRef)</td>
<td>@Html.DisplayFor(x =>x.Lines[i].Description) @Html.HiddenFor(x => x.Lines[i].Description)</td>
</tr>
}
</table>
<input type="submit" value="Submit"/>
}
其中Lines 是SupplierInvoiceMatchingDto 对象的列表,MatchLines 方法签名看起来像
public ActionResult MatchLines(IEnumerable<SupplierInvoiceMatchingDto> list)
当我点击这个视图上的提交按钮时,列表以null 的形式传递给控制器。
但是,如果我将Model 更改为List<SupplierInvoiceMatchingDto>,并将所有表行更改为x => x[i].Whatever,它会正常发布所有信息。
我的问题是:我如何让它将列表发布到控制器,同时将模型保持为 SupplierInvoiceMatchingVm,因为我需要在此视图中从模型中获取一些其他内容(为简洁起见,我已将其取出) .
注意:我删除了一些用户输入字段,它不仅仅是发布与给出的相同数据。
【问题讨论】:
标签: c# asp.net-mvc-3 razor