我有一个简单的TestController类和用户模型:
I have a simple TestController class and User model:
public class TestController : Controller { public ActionResult TestAction() { return View(); } [HttpPost] public ActionResult TestAction(User user) { return View(); } } public class User { public int Id { get; set; } public string Name { get; set; } public int Age { get; set; } }这是我的表格:
据我所知,MVC是无状态的,并且没有viewstate概念.但是,将数据发布到我的控制器后,当我返回视图时,我所有的数据都在那里.我希望有空字段,但它们都充满了已发布的数据.我不明白MVC在回发后如何知道这些值?
As far as I know MVC is stateless and it does not have a viewstate concept. But after posting the data to my controller and when I return the view, all my data is there. I expect empty fields but they are all filled with the posted data. I could not understand how MVC knows the values after postback?
推荐答案@ stephen.vakil
@stephen.vakil
从HttpPost返回View时,假定您正在处理错误情况.它将发布的数据保留在ModelState中,然后在页面上重新填充数据,以便用户可以对其进行纠正.
When you return a View from an HttpPost the assumption is that you are handling an error condition. It will keep the posted data in the ModelState and re-fill the data on the page so that the user can correct it.
更多推荐
MVC在回发后保留值
发布评论