Mvc retain values after postback

天涯浪子 提交于 2019-12-03 22:15:12

You Need to use ModelState.Clear()

public class TestController : Controller
{
    public ActionResult TestAction()
    {
        return View();
    }

    [HttpPost]
    public ActionResult TestAction(User user)
    {
        ModelState.Clear()
        return View();
    }
}

@stephen.vakil

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!