我有一个强类型ViewPage绑定到一个很简单的Model:当我在处理POST的Action里面重新生成了一个Model object,并且更改了name属性,然后 return View(model);但是在新生成的页面表单里按照:<%=Html.TextBox("name", Model.name) %>生成的输入框内容还是POST前的值,并没有更新为我重新赋予的值,但是按照:<%= Model.name%>绑定的值却是在处理POST Action里面重新赋予的值,请教这是怎么回事?
public class MyModel
{
public string name { get; set; }
}
[HandleError]
public class HomeController : Controller
{
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult About()
{
MyModel model=new MyModel();
return View(model);
}
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult About(MyModel argm)
{
MyModel model = new MyModel();
model.name = "King";
//return RedirectToAction("Index","Home");
return View(model);
}
}
<asp:Content ID="aboutContent" ContentPlaceHolderID="MainContent" runat="server">
<h2>About</h2>
<p>
<% using (Html.BeginForm())
{%>
Model.name: <%= Model.name%><br/>
<%=Html.TextBox("name", Model.name) %>
<input type="submit" value="Submit" />
<%} %>
</p>
</asp:Content>