MVC3:发布后,更新后的值不会反映在文本框中

Lal*_*lit 1 postback asp.net-mvc-3

我在我的页面上显示了一组数据.我正在为每一行显示标签和文本框.

以下是我的视图中的示例代码:

@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)
   }
}
Run Code Online (Sandbox Code Playgroud)

在Post Action中,我是更新金额(比如增加5).

    [HttpPost]
    public ActionResult Persons(PersonList presenter)
    {

        for (int index = 0; index < presenter.Persons.Count; index++)
        {
            presenter.Persons[index].Amount += 5;
        }
        return View(presenter);
    }
Run Code Online (Sandbox Code Playgroud)

此更新金额未反映在页面上.但是,如果我使用下面的代码,那么它会正确显示,如

@Model.Persons[index].Amount
Run Code Online (Sandbox Code Playgroud)

要么

<input type="text" id=@("Persons_" + index + "__Amount") name="Persons[@index].Amount " value="@Model.Persons[index].Amount" ></input>
Run Code Online (Sandbox Code Playgroud)

我想这种行为的原因是为什么会发生这种情况?

任何帮助,将不胜感激.

Gok*_*ath 5

在更新值之前,只需添加ModelState.Clear(),更新集合并返回它.