我有一個列表對象,我試圖在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