我有一个列表对象,我试图在foreach循环中显示文本框。但是,该帖子返回空对象。我看不出原因。在foreach循环中输入表单返回空模型
这里是在视图的代码
使用(Html.BeginForm( “makeTransfer”, “shareTransfer”))<%{%>
<% foreach (var i in Model.Inform)//int i = 0; i < Model.Inform.Count(); i++){ %>
<%:Html.HiddenFor(x=>i.shares, new{@value = i.shares}) %>
...
<td style = "width:20px"><%:Html.TextBoxFor(x=>i.sharesRq)%></td> cuddling
<%} %>
<%:Html.HiddenFor(x => x.accSrc, new { @value = Model.accSrc })%>
<%:Html.HiddenFor(x=>x.accDst, new{ @value = Model.accDst}) %>
Date of Transfer<%:Html.TextBoxFor(x => x.date)%>
Transfer with benefit<%:Html.CheckBoxFor(x => x.withBenefit)%>
<input type="submit" name="save" value="Save" /></div>
<input type="submit" name="cancel" value="Cancel" /></div>
<%}%>
这里是控制器
public ActionResult makeTransfer(vmTransfer transfer,string save,string cancel) {
if (cancel != null)
return RedirectToAction("startTransfer");
else if (save != null)
{
foreach (var t in transfer.Inform)
{ ...
我的问题是,transfer.Inform(从最后第二行)是一个列表,当表单发布时为空。请尽快提供帮助。
,能不能请您编辑的代码部分。 – 2011-04-14 07:54:00
请考虑灰色框上方的行,作为代码的一部分。 – merawi 2011-04-14 09:08:21