我试图从视图传递一个带有列表属性的模型,以发布后动作。该列表在帖子后返回null,但我们需要列出新项目以更新其信息。我的模型是这样的:MVC4如何将模型指令列表传递给视图
public class Person()
{
internal string Name {get;set;}
internal decimal Age {get;set;}
internal List<int> Rate {get;set;}
}
视图填充了他们目前的信息,我们使用foreach通过列表进行迭代,并产生文本框的编辑功能。当人在编辑所需值后提交时,视图将转到[HttpPost]操作,但值为空。
视图被@using(Html.BeginForm(模型))包围,并在提交时,模型被传递给帖子操作,但列表为空。所有其他值都被填充。
任何想法? P.S.我们正在使用c#和Razor View Engine 抱歉,但列表仍然没有传递给模型,这里是4循环。
@{ int i = 0;}
<table>
@for (i = 0; i < Model.VendorContracts.Count; i++)
{
if (i == 0)
{
<tr>
<th>
Vendor Contracts
</th>
<th>
Effective Date
</th>
</tr>
}
if (i < 5)
{
<tr>
<td>@Model.VendorContracts[i]
</td>
<td>@Html.TextBoxFor(model => model.EffectiveDates[i])</td>
</tr>
}
if (i == 5 || i == 10 || i == 15 || i == 20)
{
@:</table>
@:<table>
}
if (i >= 5)
{
if (i == 5 || i == 10 || i == 15 || i == 20)
{
<tr>
<th>Vendor Contracts
</th>
<th>
Effective Date
</th>
</tr>
}
<tr>
<td>
@Model.VendorContracts[i]
</td>
<td>@Html.TextBoxFor(model => model.EffectiveDates[i])</td>
</tr>
}
}
</table>
发表您的看法,以及 – ediblecode