How to clear textboxes defined with MVC HTML helpers

前端 未结 2 1582
庸人自扰
庸人自扰 2021-01-06 09:46

I can\'t figure out how to do this very simple thing: My page contains a set of textboxes that a user can fill out to add an item to a list. Then the item shows up in a drop

2条回答
  •  醉酒成梦
    2021-01-06 09:59

    This is working for me on an MVC3 site log on page.

    ModelState.Clear();
    model.UserName = string.Empty;
    model.Password = string.Empty;
    ModelState.AddModelError("", "The user name or password provided is incorrect.");
    

    This will clear the login textboxes used for password and username, and keep any model errors.

提交回复
热议问题