我有一个简单的测试应用程序:
模型:
public class Counter
{
public int Count { get; set; }
public Counter()
{
Count = 4;
}
}
控制器:
public class TestController : Controller
{
public ActionResult Increment(Counter counter)
{
counter.Count++;
return View(counter);
}
}
看法:
<form action="/test/increment" method="post">
<input type="text" name="Count" value="<%= Model.Count %>" />
<input type="submit" value="Submit" />
</form>
单击提交我得到这样的值:
5, 6, 7, 8, ...
使用 Html.TextBox 我期望相同的行为
<form action="/test/increment" method="post">
<%= Html.TextBox("Count") %>
<input type="submit" value="Submit" />
</form>
但实际上得到了
5、5、5、5。
似乎 Html.TextBox 使用 Request.Params 而不是 Model?