I've read from other posting, if a required field validator is hidden, javascript (client-side) does not validate the control as expected, however server-side is unaware that the control is hidden and thus validates the validator as false. Not sure why server-side is not notified on postback, but will accept that that's the way it is.
So, problem is the ModelState.IsValid is false because of these hidden validators. I figured no problem, I know the ModelState keys for these hidden validators, so I'll just remove the errors and set the ValidationState to Valid. It seems this does not work as the ErrorCount did not change and ModelState.IsValid is still false. I used the following code:
modelState["ModelVM.MyKey"].Errors.Clear();
modelState["ModelVM.MyKey"].ValidationState = ModelValidationState.Valid;
Do I need to refresh the ModelState? Or is there a better, cleaner way to deal with hidden required field validators? Any help would be greatly appreciated.
I'm using ASP.NET Core 2.0. Thanks.