【发布时间】:2011-11-03 18:16:14
【问题描述】:
我正在我的页面上显示一组数据。我正在为每一行显示标签和文本框。
以下是我的视图中的示例代码:
@using (Html.BeginForm())
{
<input type="submit" value="Ok" />
@for (int index = 0; index < Model.Persons.Count; index++ )
{
@Model.Persons[index].Name
@Html.TextBoxFor(m => Model.Persons[index].Amount)
}
}
在 Post Action 中,我正在更新 Amount(比如增加 5)。
[HttpPost]
public ActionResult Persons(PersonList presenter)
{
for (int index = 0; index < presenter.Persons.Count; index++)
{
presenter.Persons[index].Amount += 5;
}
return View(presenter);
}
此更新金额不会反映在页面上。 但是,如果我使用下面的代码,那么它会正确显示,例如
@Model.Persons[index].Amount
或者
<input type="text" id=@("Persons_" + index + "__Amount") name="Persons[@index].Amount " value="@Model.Persons[index].Amount" ></input>
我想知道为什么会发生这种行为的原因?
任何帮助将不胜感激。
【问题讨论】: