[HttpPost]
public ActionResult check(string UserName,string Password)
{
BSSCom_UserRegisterDTO user = new BSSCom_UserRegisterDTO();
user.Listlogindepartments = new List<BSSCom_LoginDepartmentsDTO>();
user.ListloginYears = new List<BSSCom_LoginYearDTO>();
ModelState.Remove("DepartmentCd");
ModelState.Clear();
return View(user);
}
ModelState.Clear() works as written exactly as written in the openly published documentation. ModelState is the state of a model after binding to a property in an Action method. You design does not bind a Model in the Action.
in your sample code ModelState represents the state of binding the two parameters
UserName and Password. If you check the ValueProvider, you will see an entry for each. the code:
ModelState.Remove("DepartmentCd");
makes no sense as "DepartmentCd" was not a binding parameter. The ModelState.Clear(), just clears the error collection.
Member
40 Points
158 Posts
ModelState.Clear() not working
Mar 18, 2020 07:43 AM|shijostephen|LINK
Hi,
ModelState.Clear() not working
Thanks & Regards
Shijo
All-Star
53021 Points
23599 Posts
Re: ModelState.Clear() not working
Mar 18, 2020 11:17 AM|mgebhard|LINK
ModelState.Clear() works as written exactly as written in the openly published documentation. ModelState is the state of a model after binding to a property in an Action method. You design does not bind a Model in the Action.
All-Star
58174 Points
15647 Posts
Re: ModelState.Clear() not working
Mar 18, 2020 02:55 PM|bruce (sqlwork.com)|LINK
Whats not working?
in your sample code ModelState represents the state of binding the two parameters UserName and Password. If you check the ValueProvider, you will see an entry for each. the code:
makes no sense as "DepartmentCd" was not a binding parameter. The ModelState.Clear(), just clears the error collection.
Participant
850 Points
492 Posts
Re: ModelState.Clear() not working
Mar 25, 2020 06:20 AM|AddWeb Solution|LINK
Hello shijostephen,
As per your requirement suggest a link.
A link has step by step information to clear model.
https://stackoverflow.com/questions/1775170/asp-net-mvc-modelstate-clear/1775185#answer-2678956
If you want to still any help let us know.
Thanks.